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

Hi,

as some of you know I'm coding a little tool to analyze a file and
submit it in a modified way to a website.
The thing itself is working fine except some problems which occured in
combination of thread and wxpython.

I'm using a TaskBarIcon to indicate the status of the programm, but
everytime after self.tbicon.SetIcon(ico,message)
is executed from the thread hovering the taskbar icon will cause the
whole programm to terminate and give the error from the subject on
CLI.

It would be kind of you to help me out with this - trying to be online
in #wxpython@freenode too.
-------------------------------------- Some possibly important code
blocks ---------------------------------------

class MainFrame(wx.frame)
  ...
  def __init__(self, daemon):
    self.tbicon = TaskBarIcon(self);
    self.changeicon(0,'Loading')
  ...
    import thread
    thread.start_new_thread(self.autosend, () )

  def autosend(self): # BUG !!
    import time
    import thread
    lock = thread.allocate_lock()

    while True:
      time.sleep(10)#self.settings.sendezeit)
      lock.acquire()
      self.OnDBOpen()
      self.send()
      lock.release()

  def changeicon(self,error=0,message=''):
    if error == 0:
      ico = wx.Icon('icon.gif', wx.BITMAP_TYPE_GIF)
    elif error == 1:
      ico = wx.Icon('icon_error.gif', wx.BITMAP_TYPE_GIF)
    message = 'Vertretungsplan-Updater: '+ message
    self.tbicon.SetIcon(ico,message) #BUG wenn von threading
gestartet
    self.SetIcon(ico)

class TaskBarIcon(wx.TaskBarIcon):
  TBMENU_SEND = wx.NewId()
  TBMENU_SETTINGS = wx.NewId()
  TBMENU_CLOSE = wx.NewId()

  def __init__(self, frame):
    wx.TaskBarIcon.__init__(self)
    self.frame = frame

    self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate)
    self.Bind(wx.EVT_MENU, self.OnTaskBarSend, id=self.TBMENU_SEND)
    self.Bind(wx.EVT_MENU, self.OnTaskBarSettings,
id=self.TBMENU_SETTINGS)
    self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE)

Do not execute code in the thread that creates or manipulates UI items. Instead you can do something like send a custom event to the UI object, or invoke a method in the UI thread using wx.CallAfter.

···

On 4/5/10 11:06 AM, benste wrote:

Hi,

as some of you know I'm coding a little tool to analyze a file and
submit it in a modified way to a website.
The thing itself is working fine except some problems which occured in
combination of thread and wxpython.

I'm using a TaskBarIcon to indicate the status of the programm, but
everytime after self.tbicon.SetIcon(ico,message)
is executed from the thread hovering the taskbar icon will cause the
whole programm to terminate and give the error from the subject on
CLI.

--
Robin Dunn
Software Craftsman