PDA

View Full Version : Gobject loops.



solarwind
February 29th, 2008, 02:02 AM
Hey all,

I wrote a pyGTK program (written in Python) that uses gobject loops to execute a function every 60 seconds. However, there may be cases where the function gets stuck up somewhere and needs to be killed and restarted. What's the best way to keep a check on this? Would a watchdog type method work?

I was thinking along the lines of adding another gobject loop that runs a function every five minutes that removes the old gobject loop (the one that runs every 60 seconds) and adds it again. In that way, it's guaranteed to be restarted at least every five minutes. I know this is a very crude way but I can't think of any other method. I'm new to GTK and GOBJECT so any help would be much appreciated.

By the way, the program is a python mail checker that sits in the system tray. What happens is, sometimes (due to a bad internet connection), the connection times out or disconnects and reconnects. In this case, the mail checking function freezes up or crashes and the program just sits there doing nothing and I don't get notifications. However, restarting the program works but I don't want to have to keep an eye out for the program. It's supposed to be watching out for me!

I will gladly post the source code if anyone is willing to help me.

solarwind
February 29th, 2008, 03:12 AM
Can someone please help?

nanotube
February 29th, 2008, 06:20 AM
don't know much about gtk specifically myself, but...
why don't you run the actual internet-connecting-mail-checking steps in a separate thread, that then passes the info to your main thread (through a Queue, e.g.)? that way even if the net connection dies, your main gui thread doesn't get stuck.

solarwind
February 29th, 2008, 06:24 AM
don't know much about gtk specifically myself, but...
why don't you run the actual internet-connecting-mail-checking steps in a separate thread, that then passes the info to your main thread (through a Queue, e.g.)? that way even if the net connection dies, your main gui thread doesn't get stuck.

Good idea. Thanks!

solarwind
March 2nd, 2008, 07:26 PM
don't know much about gtk specifically myself, but...
why don't you run the actual internet-connecting-mail-checking steps in a separate thread, that then passes the info to your main thread (through a Queue, e.g.)? that way even if the net connection dies, your main gui thread doesn't get stuck.

I tried the thread method but the thread stops when the app is running. It's weird, I don't know why.

imdano
March 2nd, 2008, 08:19 PM
Couldn't you just handle the exceptions (using try/except) that sometimes happen in your checking method, so that it always returns, even if it fails?

solarwind
March 2nd, 2008, 08:28 PM
Couldn't you just handle the exceptions (using try/except) that sometimes happen in your checking method, so that it always returns, even if it fails?

Tried that, it doesn't work the way I want it to... I still don't know why threading isn't working.

nanotube
March 3rd, 2008, 05:11 AM
Tried that, it doesn't work the way I want it to... I still don't know why threading isn't working.

hm well post the source (or link to it) and maybe someone can take a look. :)

solarwind
March 3rd, 2008, 05:17 AM
hm well post the source (or link to it) and maybe someone can take a look. :)

Well, this is for my gmail checker program. I don't need this anymore as I am using a different method now. Thanks for the help anyway guys!

If anyone's interested, my program is called ggmail http://www.blog.solarwind.metafy.org/category/ggmail/

nanotube
March 3rd, 2008, 06:49 AM
Well, this is for my gmail checker program. I don't need this anymore as I am using a different method now. Thanks for the help anyway guys!

If anyone's interested, my program is called ggmail http://www.blog.solarwind.metafy.org/category/ggmail/

care to share this new method that worked for you?

(btw, your ggmail looks neat. :) )

solarwind
March 3rd, 2008, 06:52 AM
care to share this new method that worked for you?

(btw, your ggmail looks neat. :) )

The new method is basically calling wget (instead of old urllib2 and sax method) with timeout options and checking for errors that way so the program doesn't get stuck up. If there is a network problem, wget will time out and return nothing in which case my program will detect that and try again later. Wget is so nice!