Passing arguments to threading objects
Alexander Skwar
news.ASkwar at DigitalProjects.com
Tue Apr 23 18:39:14 EDT 2002
Hello.
I'm currently learning Python 2.2 (on Linux) and just started tinkering
around with threads. I've got the following code:
import threading
import random
import time
def mache(name, max):
for i in range(max):
print `name` + ': ' + `i`
time.sleep(random.random())
class myThread(threading.Thread):
def run(self, name, max):
for i in range(max):
print `name` + ': ' + `i`
for t_num in range(10):
# t = threading.Thread(target = mache, args = (t_num, 10))
t = myThread(args = (t_num, 10))
t.start()
As you can see, I created a subclass "myThread" of threading.Thread.
There, I'd like to overwrite the run method and pass two parameters into
it. This obviously does not work.
However, when I use the base class as in the commented out line and set a
target which also requires two arguments, I get what I'd expect to get.
When I subclass threading.Thread, how can I access the args parameter
passed to the constructor?
Thanks,
Alexander Skwar
--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.iso-top.de | Jabber: askwar at a-message.de
iso-top.de - Die günstige Art an Linux Distributionen zu kommen
Uptime: 16 hours 48 minutes
More information about the Python-list
mailing list