urllib.urlopen blocking?

D

Dominik Gabi

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.
 
A

Antoine Pitrou

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)?
 
D

Dominik Gabi

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...
 
A

Antoine Pitrou

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top