Python:在 X 服务器 :0.0 上发生致命的 IO 错误 11(资源暂时不可用)

8

我正在尝试读取一些图片(后续打算对它们进行一些操作),当图片被读入内存时,我想要显示一个动态的 '.gif' 图片。为此,我必须使用线程。现在出现了错误:

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

有时会出现错误:
python: Fatal IO error 0 (Success) on X server :0.0.

(是的,错误信息几乎交替更改)我不知道为什么会出现这个错误以及如何将其删除。

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()

如果我替换这一行
dirim[infile]=wx.Bitmap(path+infile)

附加虚线:

dirim[infile]=infile

它工作得很好,没有错误。

如果我替换这一行

thread.start_new_thread(grabImages, ( ))

使用类似以下的东西:

grabImages()

它很好地运行着,没有错误。唯一的问题是我无法显示动画gif图像。

我尝试了删除~ / .gconf / desktop / gnome / peripherals,如链接中由joaquin提到的那样。它无效...

我还尝试了“xhost +”。我在网络上找到它。仍然没有成功。

请告诉我这段代码发生了什么,并建议一个解决方案。我正在使用Ubuntu 10.04操作系统。

目录权限为:

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

Python版本的详细信息如下: Python 2.6.5 (r265:79063, 2010年4月16日, 13:09:56) [GCC 4.4.3] 在linux2上运行


这是几年后的事了,但我想补充一下,我也遇到了同样的错误(但是是在PySide中),对我来说,它与this question有关。所以基本上你不能在主线程之外调用绘制函数,这就是为什么当你用其他东西替换位图时它能工作的原因。 - iled
2个回答

3

您的代码在我使用的win7操作系统、wxpython 2.8.12.1和python 2.6.7环境下运行良好,使用了Spe版本0.8.4.i,只要将图片放在脚本目录下(我使用了自己的动画gif和png图片)。

唯一需要改变的是除了导入wx之外,还需要导入animate (from wx import animate)并使用它。

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

替代

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

编辑:有几个人出现了和你一样的错误信息,例如这里这里这里。我认为最后一个可能与在Linux中使用带GUI框架的线程有关(这里也有相关内容)。您可以搜索错误字符串以获取更多信息,或者在SO上提出具体问题,以错误字符串作为主题。咦!已经有一个


目录权限为: drwxr-xr-x 图片 drwxr-xr-x 足球 它不是受保护的目录或服务器。导入如下: import wx, wx.animate import thread import os我正在使用 Ubuntu 10.04。 - anshul410
根据您的建议,我已编辑了代码:它会出现以下错误:NameError:未定义全局名称“animate”。 - anshul410
anshul@anshul-laptop:/project$ python gif3.py ./images/soccer/0.jpg python:在X服务器 :0.0 上发生致命的IO错误0(成功)。 anshul@anshul-laptop:/project$ python gif3.py ./images/soccer/0.jpg python:在X服务器 :0.0 上发生致命的IO错误11(资源暂时不可用)。 anshul@anshul-laptop:~/project$ python gif3.py ./images/soccer/0.jpg python:在X服务器 :0.0 上发生致命的IO错误0(成功)。 错误消息交替更改 (:mystery ) .. :| - anshul410

3

不知道这是否与您的问题有关,但您应该在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()

==编辑==

我并没有看到你在另一个线程中实例化了一个wx.Bitmap。这是不好的。请尝试使用以下方法:

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)

仍然显示相同的两个错误: 致命IO错误0 致命IO错误11 - anshul410
@anshul410 即使使用了CallAfter,问题仍然存在吗?这对我解决了一个类似的问题。 - Kyle Strand

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接