Threads, again

Alexander K x at y.z
Thu Oct 19 01:55:59 EDT 2000


Alex McHale <daimun at home.com> wrote in message
news:dzsH5.153671$Qx4.5060109 at news1.rdc1.il.home.com...
> This may be a bit of a dumb question - but I, for the life of
me, can't
> understand why, when using the thread module, start_new_thread
will only
> pass a tuple of arguments to the function.  Can anyone explain
this to me?
> Does this mean any function I want to thread, has to take 3
arguments?
>

no. the start_new_thread function can take 3 args, but the func
you want to thread can take arbitraryly many.
it looks like this, right?

start_new_thread (function, args[, kwargs])

function is the name of the to-be-threaded function. args is a
tuple (containing the args for your function), and kwargs is
optional (havent used it myself:)).

so if you want to thread this:
>>> my_funk('blabla', 42)

you would write this:
>>> start_new_thread(my_funk, ('blabla', 42))

the tuple you pass as second argument can be whatever suits your
function... (i think:))

  / alex k

ps. i am a beginner programmer myself, so no guarantees...





More information about the Python-list mailing list