Prev: reading xml from python
Next: Slice last char from string without raising exception on empty string(Re: Extract all words that begin with x)
From: Dominik Gabi on 11 May 2010 09:22 Hi, I'm new to python and have been playing around with it for a few days now. So please forgive me if this is a stupid question :) I've tried writing a little application with pygtk and urllib. When a button is clicked I create a new thread that opens an URL with urllib. The new thread is running but as soon as I call urllib.urlopen("https://someurl", postdata) it blocks. It blocks until I do something in the interface (e.g. click another button). I've obviously missed something here. The interface should not interfere with anything that runs in an other thread!? Here are a few extracts from my code: def send_message(self, widget, data=None): # This is called when the button is clicked ... threading.Thread(target=message.send).start() ... def send(self): # This is executed in its own thread ... postdata = urllib.urlencode(data) # This line is the last one executed resp = urllib.urlopen('https://theurl', postdata) Regards, Dominik.
From: Antoine Pitrou on 11 May 2010 09:54 On Tue, 11 May 2010 06:22:29 -0700 (PDT) Dominik Gabi <dkgispam(a)gmail.com> wrote: > > I'm new to python and have been playing around with it for a few days > now. So please forgive me if this is a stupid question :) > > I've tried writing a little application with pygtk and urllib. For the record, have you tried calling gobject.threads_init() at the beginning of your application (just after importing all modules)?
From: Dominik Gabi on 11 May 2010 10:35 > For the record, have you tried calling gobject.threads_init() at the > beginning of your application (just after importing all modules)? I haven't... now it works, thanks :) Any tips on how to avoid mistakes like that in the future? I'm somewhat confused as to how I was supposed to get this out of the documentation...
From: Antoine Pitrou on 11 May 2010 10:55
On Tue, 11 May 2010 07:35:52 -0700 (PDT) Dominik Gabi <dkgispam(a)gmail.com> wrote: > > For the record, have you tried calling gobject.threads_init() at the > > beginning of your application (just after importing all modules)? > > I haven't... now it works, thanks :) Any tips on how to avoid mistakes > like that in the future? I'm somewhat confused as to how I was > supposed to get this out of the documentation... I'm afraid I don't know the answer. I'm not a pygtk expert at all, I just remember that I had to do that in one of my applications long ago, otherwise pygtk doesn't support Python threads properly. Regards Antoine. |