【问题标题】:python: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.0python:X服务器上的致命IO错误11(资源暂时不可用):0.0
【发布时间】: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


【解决方案1】:

当图像位于脚本目录中时,您的代码在 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)

编辑:在很多情况下,人们会收到与您相同的错误消息,例如 hereherehere。最后一个让我认为它可能与在 linux (see also here something related) 中使用带有 gui 框架的线程有关。您应该搜索错误字符串以查看是否可以获得更多信息或以错误字符串为主题询问有关 SO 的特定问题。唔!有already one

【讨论】:

  • 目录权限是:drwxr-xr-x images drwxr-xr-x football 它不是受保护的目录或服务器。导入是:import wx, wx.animate import thread import os 我使用的是 ubuntu 10.04
  • 根据您的建议,我已经编辑了代码:它给出:NameError: global name 'animate' is not defined
  • ` anshul@anshul-laptop:~/project$ python gif3.py ./images/soccer/0.jpg python:X 上的致命 IO 错误 0 (成功)服务器:0.0。 anshul@anshul-laptop:~/project$ python gif3.py ./images/soccer/0.jpg python: X server :0.0 上的致命 IO 错误 11 (资源暂时不可用)。 anshul@anshul-laptop:~/project$ python gif3.py ./images/soccer/0.jpg python: Fatal IO error 0 (Success) on X server :0.0. ` 错误信息交替变化 (:mystery ) .. :|
【解决方案2】:

不知道它是否与您的问题有关,但您应该实例化对话框并在创建 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)

【讨论】:

  • 它仍然显示相同的两个错误:Fatal IO Error 0 Fatal IO Error 11
  • @anshul410 即使是CallAfter?这为我解决了一个类似的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 1970-01-01
  • 1970-01-01
  • 2012-11-13
  • 1970-01-01
  • 1970-01-01
  • 2018-03-03
相关资源
最近更新 更多