如果在线程内运行,urllib2 opener 会挂起 [英] urllib2 opener hangs if run inside a thread
问题描述
我有一个运行良好的代码(连接到页面,获取 PHPSESSID).当我将该代码放入一个函数中时,然后创建了一个线程:
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()
代码挂了
f = opener.open(req)
有什么想法吗?
当我强制关闭应用程序时,它会完成所有内容并在终端中无错误地打印所有内容.为什么它只挂在线程中的特定行上.它不在线程之外.
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 .
推荐答案
好的,我只是在这里转发评论,以便问题得到解决.
Okay, I just repost the comment here so that the question can get solved.
正如其他关于 pygtk
和 threading
的帖子所提到的,一些看起来很奇怪的挂起行为似乎与没有实现以下行有关:>
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()
在调用 gtk 主循环之前.请注意,虽然已经在 stackoverflow 上的其他问题上报告了此解决方案可能适用于 Windows,也可能不适用于 Windows.
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.
这篇关于如果在线程内运行,urllib2 opener 会挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!