【发布时间】:2011-11-25 23:50:11
【问题描述】:
我正在尝试读取一些图像(稍后打算对它们执行一些任务),而图像正在被读入内存。我想显示一个动画“.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 ..
如joaquin 给出的link 中所述,我已尝试删除 ~/.gconf/desktop/gnome/peripherals。它不起作用.. 我也试过 '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 有关。所以基本上你不能在主线程之外调用绘图函数,这就是为什么当你用其他东西替换 Bitmap 时它起作用的原因。
标签: python multithreading wxpython animated-gif