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

2024-10-06 11:20:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着读一些图像(稍后打算做一些任务),当图像被读入记忆时。我想显示一个动画的“.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给出的link中所述。它不起作用。。 我也试过“xhost+”。我在网上找到的。仍然没有成功。

请告诉我代码中发生了什么。。并提出解决方案 我正在使用Ubuntu10.04OS。 目录权限为:

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

Python verion的详细信息是: Python2.6.5(r265:7906320010年4月16日,13:09:56) [GCC 4.4.3]关于linux2


Tags: path图像importselfiddef错误动画
2条回答

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

除了wx和use之外,我只需要导入animate(from wx import animate

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

而不是

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

编辑:有些人的错误信息与您的相同,例如hereherehere。最后一个让我认为它可能与在linux(see also here something related)中使用带有gui框架的线程有关。你应该用google搜索错误字符串,看看你是否能得到更多的信息,或者用错误字符串作为主题来问一个特殊的问题。乌夫!有already one

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

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)

相关问题 更多 >