python: X服务器上的致命IO错误11(资源暂时不可用):0.0。

时间:2022-09-22 13:40:29

I am trying to read some Images(and later intend to do some task on them), and while Images are being read into memory. I want to display a animated '.gif' Image. For that purpose I had to use Threads. Now it is giving Error :

我试着读一些图片(稍后打算在上面做一些任务),而图像正在被读入内存。我想展示一个动画。gif图像。为此,我不得不使用线程。现在它出现了错误:

python: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0.

And some times it gives Error :

有时会出错

python: Fatal IO error 0 (Success) on X server :0.0.

(Yes Error message changes almost alternately) I have no idea as to why this error Occurred and how to remove it.

(是的,错误消息几乎是交替发生的)我不知道为什么会出现这个错误,以及如何删除它。

import wx
from wx import animate
import thread
import os
class AniGif(wx.Dialog):
   def __init__(self, parent, id, title):
      wx.Dialog.__init__(self, parent, id, title, size=(300, 300))
      buttonOk = wx.Button(self, id=3, label="Ok", pos=(75, 50), size=(50, 50))
      self.Bind(wx.EVT_BUTTON, self.OnClick, id=3)

   def OnClick(self, event) :
      clock = "loading.gif"
      showclock = wx.animate.GIFAnimationCtrl(self, -1, clock)
      showclock.Play()
      thread.start_new_thread(grabImages, ( ))

def grabImages():
    global dirim
    dirim = {}
    path = './images/soccer/'
    listing = os.listdir(path)
    for infile in listing:
        if len(infile)>4 and infile[-4:]=='.jpg' :
            print path+infile
            dirim[infile]=wx.Bitmap(path+infile)

app = wx.App()
dia = AniGif(None, -1, "Ani Gif")
dia.ShowModal()
dia.Destroy()
app.MainLoop()

if I replace this line

如果我替换这条线。

dirim[infile]=wx.Bitmap(path+infile)

with a dummy line :

用假线:

dirim[infile]=infile

It work's fine , No Error.

工作很好,没有错误。

And if I replace this line

如果我替换这条直线。

thread.start_new_thread(grabImages, ( ))

with a something like :

比如:

grabImages()

It work's fine , No Error. Only Problem I am not able to display animated gif then ..

工作很好,没有错误。只有问题,我不能显示gif动画。

I have tried removing ~/.gconf/desktop/gnome/peripherals as mentioned in the link given by joaquin. It doesn't work .. and I also tried 'xhost +' . I found from somewhere on the net. Still no success.

我已经试过移走~/。gconf/桌面/gnome/外围设备,如joaquin所提供的链接。它不工作. .我还尝试了xhost +。我从网上的某个地方找到的。仍然没有成功。

Please tell what is happening in this code .. and suggest a solution I am using ubuntu 10.04 OS. And directory permissions are :

请告诉我这段代码中发生了什么。建议我使用ubuntu 10.04操作系统。目录权限是:

drwxr-xr-x images
drwxr-xr-x soccer

Python verion's detail are : Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2

Python verion的细节是:Python 2.6.5 (r265:79063, 2010年4月16日,13:09:56)[GCC 4.4.3]在linux2上。

2 个解决方案

#1


2  

Your code works perfect for me in win7 with wxpython 2.8.12.1 and python 2.6.7 runing on Spe version 0.8.4.i when the images are located in the script directory (I used my own animated gif and a png).

您的代码在win7中非常适合我,wxpython 2.8.12.1和python 2.6.7在Spe版本0.8.4上运行。当图像位于脚本目录中时(我使用了自己的gif动画和png)。

The only change I needed was to import animate (from wx import animate) in addition to wx and use

我所需要的唯一更改是,除了wx和使用之外,导入动画(从wx导入动画)。

showclock = animate.GIFAnimationCtrl(self, -1, clock)

instead of

而不是

showclock = wx.animate.GIFAnimationCtrl(self, -1, clock)

Edit: There are several cases of people having the same error messsages as yours like here and here and here. This last one makes me think that it could be related with the use of threads with a gui framework in linux (see also here something related). You should google the error string to see if you can get some more information or ask an especific question on SO with the error string as the subject. Uf! there is already one !

编辑:在这里,这里和这里,有几个人有相同的错误消息。最后一个让我认为它可能与在linux中使用gui框架的线程有关(参见这里的相关内容)。您应该将错误字符串谷歌查看是否可以获得更多的信息,或者以错误字符串作为主题询问一个特定的问题。佛罗里达大学!已经有一个了!

#2


2  

Don't know if it's related to your problem but you should instantiate the dialog and call its ShowModal after the wxApp is created:

不知道它是否与你的问题有关,但你应该在wxApp创建后实例化对话框并调用它的ShowModal:

class App(wx.App):
    def OnInit(self):
        dia = AniGif(None, -1, "Ani Gif")
        try:
            dia.ShowModal()
        finally:
            dia.Destroy()
        return True

App(0).MainLoop()

== edit ==

= = = =进行编辑

I didn't see you instantiated a wx.Bitmap from another thread. This is bad. Try this instead:

我没有看到你实例化一个wx。位图从另一个线程。这是不好的。试试这个:

def grabImages():
    global dirim
    dirim = {}
    def addToDict(key, path):
        dirim[key] = wx.Bitmap(path)
    path = './images/soccer/'
    listing = os.listdir(path)
    for infile in listing:
        if len(infile)>4 and infile[-4:]=='.jpg' :
            print path+infile
            wx.CallAfter(addToDict, infile, path+infile)

#1


2  

Your code works perfect for me in win7 with wxpython 2.8.12.1 and python 2.6.7 runing on Spe version 0.8.4.i when the images are located in the script directory (I used my own animated gif and a png).

您的代码在win7中非常适合我,wxpython 2.8.12.1和python 2.6.7在Spe版本0.8.4上运行。当图像位于脚本目录中时(我使用了自己的gif动画和png)。

The only change I needed was to import animate (from wx import animate) in addition to wx and use

我所需要的唯一更改是,除了wx和使用之外,导入动画(从wx导入动画)。

showclock = animate.GIFAnimationCtrl(self, -1, clock)

instead of

而不是

showclock = wx.animate.GIFAnimationCtrl(self, -1, clock)

Edit: There are several cases of people having the same error messsages as yours like here and here and here. This last one makes me think that it could be related with the use of threads with a gui framework in linux (see also here something related). You should google the error string to see if you can get some more information or ask an especific question on SO with the error string as the subject. Uf! there is already one !

编辑:在这里,这里和这里,有几个人有相同的错误消息。最后一个让我认为它可能与在linux中使用gui框架的线程有关(参见这里的相关内容)。您应该将错误字符串谷歌查看是否可以获得更多的信息,或者以错误字符串作为主题询问一个特定的问题。佛罗里达大学!已经有一个了!

#2


2  

Don't know if it's related to your problem but you should instantiate the dialog and call its ShowModal after the wxApp is created:

不知道它是否与你的问题有关,但你应该在wxApp创建后实例化对话框并调用它的ShowModal:

class App(wx.App):
    def OnInit(self):
        dia = AniGif(None, -1, "Ani Gif")
        try:
            dia.ShowModal()
        finally:
            dia.Destroy()
        return True

App(0).MainLoop()

== edit ==

= = = =进行编辑

I didn't see you instantiated a wx.Bitmap from another thread. This is bad. Try this instead:

我没有看到你实例化一个wx。位图从另一个线程。这是不好的。试试这个:

def grabImages():
    global dirim
    dirim = {}
    def addToDict(key, path):
        dirim[key] = wx.Bitmap(path)
    path = './images/soccer/'
    listing = os.listdir(path)
    for infile in listing:
        if len(infile)>4 and infile[-4:]=='.jpg' :
            print path+infile
            wx.CallAfter(addToDict, infile, path+infile)