urllib2 opener hangs if run inside a thread

╄→гoц情女王★ 提交于 2019-12-02 16:29:57

问题


I have a code that is running fine (connect to a page , get PHPSESSID) . when i put that code in a function , then made a thread of it :

Gdk.threads_enter()
threading.Thread(target=self.do_login,args=()).start()
Gdk.threads_leave()

the code hangs on

f = opener.open(req)

any ideas why ?

when i force close the application , it completes everything and prints everything in the terminal without errors . why does it hang on that particular line in thread only . it does not outside of a thread .


回答1:


Okay, I just repost the comment here so that the question can get solved.

As has been mentioned on other posts regarding pygtk and threading, several hang-behaviours that seem strange appears to be related to not having implemented the following line:

gobject.threads_init()

Before calling the gtk main-loop. Note though that it has been reported on other questions here on stackoverflow that this solution may or may not work for Windows.



来源:https://stackoverflow.com/questions/12708039/urllib2-opener-hangs-if-run-inside-a-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!