Main index > Python programming > Errors when quitting

By dessaya (Desklet Author), on Thu Jul 7 17:33:33 2005: Errors when quitting.

Sometimes when closing the desklet via menu->Quit, I get an error raised by adesklets. For example, one of this cases involves the following code:

Code:

def leave_notify(self, delayed, x, y):
    if self.pointer_over_icon:
        self.pointer_over_icon = False
        self._display()


When I select menu->Quit, leave_notify() is called, and I get the following traceback:

Code:

Traceback (most recent call last):
  File "./doityourself.py", line 411, in ?
    Events(dirname(__file__)).pause()
  File "/usr/lib/python2.3/site-packages/adesklets/events_handler.py", line 228, in pause
    posix_signal.pause()
  File "/usr/lib/python2.3/site-packages/adesklets/events_handler.py", line 214, in _fire_event
    [x for x in
  File "./doityourself.py", line 247, in leave_notify
    self._display()
  File "./doityourself.py", line 300, in _display
    adesklets.context_set_font(self._font)
  File "/usr/lib/python2.3/site-packages/adesklets/commands.py", line 384, in context_set_font
    return comm.out()
  File "/usr/lib/python2.3/site-packages/adesklets/commands_handler.py", line 93, in out
    output=self.__comm.out(.01)
  File "/usr/lib/python2.3/site-packages/adesklets/communicator.py", line 91, in out
    raise ADESKLETSError(1)


Something similar happens sometimes, but involving the alarm() function, which also calls _display(). Am I doing something wrong? It seems that I shouldn't call _display() so happily... How can I tell if it is safe to call it?
Thanks in advance,
Diego

By syfou (Core Developer & Desklet Author), on Thu Jul 7 20:18:34 2005.

dessaya wrote:


Am I doing something wrong? It seems that I shouldn't call _display() so happily...

You are not doing anything wrong, as long as your _display() function doesn't take too much time to return (which is a purely qualitative criteria, largely depending of the desklet).

Let me explain briefly: a desklet written in python is at least composed of two process: a driving python interpreter, executing the desklet script, and a self-contained adesklets interpreter that performs all the graphical operations. When a user interactively selects the Quit option from the contextual menu, the adesklets interpreter exits right away, notifying the python process (sending back a quit event to it).

What happens in your case is that all events notifications are blocked by default during the execution of any event that is not alarm(); therefore, trying to continue sending commands to the adesklets interpreter results in a "adesklets process exited" exception, which is perfectly right and fine.

dessaya wrote:


How can I tell if it is safe to call it?


You cannot know, unless it happens: it is the whole point of raising an exception. User manually killing a desklet is an exceptional, asynchronous event (normally, people do not quit desklets this way very often: hence it would be very wasteful to check for this all the time). Of course, nothing prevents you from catching the exception and handling things in a less "console-noisy" way. Most of the time, there is little use doing so (and I personally never did), since most of desklets do not handle any persistent information in a way that would interleave generating graphic output and modifing the data... Yours,


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.