Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python urllib.urlopen-won';不能在线程上执行_Python_Multithreading_Urllib - Fatal编程技术网

Python urllib.urlopen-won';不能在线程上执行

Python urllib.urlopen-won';不能在线程上执行,python,multithreading,urllib,Python,Multithreading,Urllib,我正在使用线程,我需要下载一个带有线程的网站。我也有一个线程发送请愿书的网站,但不等待答复。 不需要等待的是: class peticion(Thread): def __init__(self, url): Thread.__init__(self) self.url = url def run(self): f = urllib.urlopen(self.url) f.close() 这一个可以正常工作,但是

我正在使用线程,我需要下载一个带有线程的网站。我也有一个线程发送请愿书的网站,但不等待答复。 不需要等待的是:

class peticion(Thread):
    def __init__(self, url):
        Thread.__init__(self)
        self.url = url

    def run(self):
        f = urllib.urlopen(self.url)
        f.close()
这一个可以正常工作,但是必须等待响应的一个需要一些随机时间来完成,从5秒到2分钟,否则它可能永远不会完成。这是一节课:

class playerConn(Thread):
    def __init__(self, ev):
        Thread.__init__(self)
        self.ev = ev

    def run(self):
        try:
            params = urllib.urlencode('''params go here''')
            f = urllib.urlopen('''site goes here''')
            resp = f.read()
            f.close()
        finally:
            # do something with the response
无论我是否使用try…finally语句,它都不起作用,
urlopen
函数后面的代码将无法执行


我能做什么?

似乎只是URL有问题,代码很好,似乎没有做错什么。 我打赌你在网站上遇到了一些问题,可能是404或类似的问题。
尝试在localhost中打开一些东西,只是为了测试。

我刚刚尝试了您的代码,它对我很有效,基本上与编写的一样。也许在打开url时检查错误,比如404之类的?