about blog projects papers interests other
Random Articles

Bored? See this sites!

Python Threads

Category: Programming
By on 2008-06-01 | Digg it!

Python threads are surprisingly more simple than I imagined.

To use them, first create anything you want in a thread as it's own class.

(sorry for not including tabs, should be easy to figure out)

class serverThread( threading.Thread ):
def run(self):
server = SocketServer.ThreadingTCPServer(('localhost', 5000), RequestHandler)
server.serve_forever()

Making sure that (threading.Thread) is in the constructor. You can also implement __init__ if you need it.

Then just call
serverThread().start()

oh and make sure to "import threading"