I am new to both python, and to threads. I have written python code which acts as a web crawler and searches sites for a specific keyword. My question is, how can I use thre
Starting a thread is easy:
thread = threading.Thread(function_to_call_inside_thread)
thread.start()
Create an event object to notify when you are done:
event = threading.Event()
event.wait() # call this in the main thread to wait for the event
event.set() # call this in a thread when you are ready to stop
Once the event has fired, you'll need to add stop() methods to your crawlers.
for crawler in crawlers:
crawler.stop()
And then call join on the threads
thread.join() # waits for the thread to finish
If you do any amount of this kind of programming, you'll want to look at the eventlet module. It allows you to write "threaded" code without many of the disadvantages of threading.