8

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

Community
  • 1
  • 1
anshul410
  • 824
  • 2
  • 11
  • 23
  • This comes a few years later, but I would like to add that I had the same error (but with PySide) and, for me, it was related to the [this question](http://stackoverflow.com/questions/8649233/threading-it-is-not-safe-to-use-pixmaps-outside-the-gui-thread). So basically you can't call draw functions outside of the main thread, and that's why it worked when you replaced Bitmap with something else. – iled Feb 04 '15 at 01:29

2 Answers2

3

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 !

Community
  • 1
  • 1
joaquin
  • 82,968
  • 29
  • 138
  • 152
  • The directory permissions are : drwxr-xr-x images drwxr-xr-x soccer It isn't a protected directory or server. imports are : import wx, wx.animate import thread import os I am using ubuntu 10.04 – anshul410 Nov 26 '11 at 01:30
  • as per your suggestion I have edited the code : It gives : NameError: global name 'animate' is not defined – anshul410 Nov 26 '11 at 01:38
  • ` anshul@anshul-laptop:~/project$ python gif3.py ./images/soccer/0.jpg python: Fatal IO error 0 **(Success)** on X server :0.0. anshul@anshul-laptop:~/project$ python gif3.py ./images/soccer/0.jpg python: Fatal IO error 11 **(Resource temporarily unavailable)** on X server :0.0. anshul@anshul-laptop:~/project$ python gif3.py ./images/soccer/0.jpg python: Fatal IO error 0 **(Success)** on X server :0.0. ` error message changes alternately (:mystery ) .. :| – anshul410 Nov 26 '11 at 02:12
3

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)
fraca7
  • 1,178
  • 5
  • 11