[Tutor] Simple thread

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Feb 18 16:29:59 EST 2004



On Tue, 17 Feb 2004, Luiz Siqueira Neto wrote:

> I can't remember but I believe that have a simple thread object for make
> some like this:
>
> t = thread(myObject)


Hi Luiz,


Are you trying to make threads in Python?  There's documentation here:

    http://www.python.org/doc/lib/module-threading.html


Here's a short example that shows how to make a thread that runs off a
function:


###
>>> def myfunction():
...     while 1:
...         print "foo"
...         time.sleep(5)
...
>>> t = threading.Thread(target=myfunction)
>>> t.start()
>>> foo

>>> foo
###


And now there's a thread that's printing 'foo' throughout the rest of the
interpreter session.  Not really useful, but at least it's illustrative.
*grin*


Is this what you're asking?



Good luck!




More information about the Tutor mailing list