Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to read some Images(and later intend to do some task on them), and while Images are being read into memory. I want to display a animated '.gif' Image. For that purpose I had to use Threads. Now it is giving Error :

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

And some times it gives Error :

python: Fatal IO error 0 (Success) on X server :0.0.

(Yes Error message changes almost alternately) I have no idea as to why this error Occurred and how to remove it.

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

if I replace this line

dirim[infile]=wx.Bitmap(path+infile)

with a dummy line :

dirim[infile]=infile

It work's fine , No Error.

And if I replace this line

thread.start_new_thread(grabImages, ( ))

with a something like :

grabImages()

It work's fine , No Error. Only Problem I am not able to display animated gif then ..

I have tried removing ~/.gconf/desktop/gnome/peripherals as mentioned in the link given by joaquin. It doesn't work .. and I also tried 'xhost +' . I found from somewhere on the net. Still no success.

Please tell what is happening in this code .. and suggest a solution I am using ubuntu 10.04 OS. And directory permissions are :

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

Python verion's detail are : Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2

like image 972
anshul410 Avatar asked Nov 25 '11 23:11

anshul410


2 Answers

Your code works perfect for me in win7 with wxpython 2.8.12.1 and python 2.6.7 runing on Spe version 0.8.4.i when the images are located in the script directory (I used my own animated gif and a png).

The only change I needed was to import animate (from wx import animate) in addition to wx and use

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

instead of

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

Edit: There are several cases of people having the same error messsages as yours like here and here and here. This last one makes me think that it could be related with the use of threads with a gui framework in linux (see also here something related). You should google the error string to see if you can get some more information or ask an especific question on SO with the error string as the subject. Uf! there is already one !

like image 161
joaquin Avatar answered Nov 04 '22 00:11

joaquin


Don't know if it's related to your problem but you should instantiate the dialog and call its ShowModal after the wxApp is created:

class App(wx.App):
    def OnInit(self):
        dia = AniGif(None, -1, "Ani Gif")
        try:
            dia.ShowModal()
        finally:
            dia.Destroy()
        return True

App(0).MainLoop()

== edit ==

I didn't see you instantiated a wx.Bitmap from another thread. This is bad. Try this instead:

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)
like image 28
fraca7 Avatar answered Nov 03 '22 22:11

fraca7