Python Process Blocked By Urllib2
I set up a process that read a queue for incoming urls to download but when urllib2 open a connection the system hangs. import urllib2, multiprocessing from threading import Thread
Solution 1:
The issue here is not urllib2, but the use of the multiprocessing module. When using the multiprocessing module under Windows, you must not use code that runs immediately when importing your module - instead, put things in the main module inside a if __name__=='__main__'
block. See section "Safe importing of main module" here.
For your code, make this change following in the downloader module:
#....def start():
global download_worker
download_worker = Process(target=downloader, args=(url_queue, page_queue))
download_worker.start()
And in the main module:
import moduleif __name__=='__main__':
module.start()
module.url_queue.put('http://foobar1')
#....
Because you didn't do this, each time the subprocess was started it would run the main code again and start another process, causing the hang.
Post a Comment for "Python Process Blocked By Urllib2"