2011-11-25 40 views
6

我正在嘗試讀取一些圖像(並且稍後打算對它們執行一些任務),並且正在將圖像讀入內存。我想顯示一個動畫'.gif'圖像。爲此,我必須使用線程。現在,它是給錯誤:python:在X服務器上發生致命IO錯誤11(資源暫時不可用):0.0

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,如link給出的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秒) [4.4.3 GCC]上linux2上

+0

這都幾年過去了,但我想補充一點,我有同樣的錯誤(但PySide),對我來說,這是關係到[這個問題](HTTP ://stackoverflow.com/questions/8649233/threading-it-is-not-safe-to-use-pixmaps-outside-the-gui-thread)。所以基本上你不能在主線程之外調用draw函數,這就是爲什麼當你用別的東西替換Bitmap的時候它的工作原理。 – iled

回答

2

當代碼位於腳本目錄(我使用了我自己的動畫GIF和PNG)時,您的代碼在win7中完美適用於wxpython 2.8.12.1和python 2.6.7,運行在Spe版本0.8.4.i上。

我所需要的唯一的變化是,除了WX導入動畫(from wx import animate),並使用

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

,而不是

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

編輯:有其人的幾種情況像您的hereherehere一樣的錯誤消息。最後一個讓我認爲它可能與linux中使用gui框架的線程相關(see also here something related)。你應該谷歌的錯誤字符串,看看你是否可以得到一些更多的信息或要求SO的錯誤字符串作爲主題的特定問題。 UF!有already one

+0

目錄權限爲: drwxr-xr-x images drwxr-xr-x soccer 它不是受保護的目錄或服務器。 進口: 進口WX,wx.animate 進口螺紋 進口OS 我使用Ubuntu 10.04 – anshul410

+0

按照你的建議,我已編輯的代碼: 它提供了: NameError:全局名稱「動畫」沒有定義 – anshul410

+0

from wx import animate – joaquin

2

不知道它關係到你的問題,但你應該實例化的對話框,並調用它的ShowModal創建後wxApp:

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) 
+0

它仍然顯示相同的兩個錯誤: 致命IO錯誤0 致命IO錯誤11 – anshul410

+0

@ anshul410即使使用'CallAfter'?這爲我解決了類似的問題。 –

相關問題