Need a better way to pause a thread
Chris Liechti
cliechti at gmx.net
Wed Jul 24 12:30:49 EDT 2002
mnations at airmail.net (Marc) wrote in
news:4378fa6f.0207240725.2e589b1e at posting.google.com:
> However you did it the following way:
>> #now you can feed your thread with work:
>> q.put( (time.sleep, 1) )
>> q.put( (sys.stdout.write, "Hello its the thread speaking up") )
>
> Basically it appears the format is the command placed in nested ()
> with things that would be passed thru as parameters being delimited by
> commas.
thats a tuple, you could also use a list instead.
the function or method that is placed as first arg is not called (no
braces) so that you get a callable which you can use later (in the thread)
> Is this a general format that will work for all commands, or
> is there a place I can check the format? There are several examples of
> queues I've found but none showing all the ways you can pass commands
> through.
passing a callable with its argument seemed to be the simplest way. other
reasonable formats would have been:
(callable, [listofargs])
and/or
(callable, [listofargs], {dictwithkeywordargs})
for which you could use:
if len(whattodo) == 3:
l[0](*l[1], **l[2])
if len(whattodo) == 2:
l[0](*l[1])
else:
l[0]()
the * and ** syntax is a shortcut for the builtin function "apply". look
there if you what more infos about that.
don't know a place to look up exactly that, but i think its a solution many
people here would have brought up ("do the simplest thing that could
possibly work"). snipets for various problems may be found in the Python
Cookbook (online: http://www.activestate.com/ASPN/Python/Cookbook/ or
printed)
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list