PythonCard timer/thread tutorial

Mike Driscoll kyosohma at
Thu Dec 25 01:59:23 CET 2008

On Dec 24, 4:56 pm, Sponge Nebson <neb... at> wrote:
> Hello all,
> This is my first post. Nice to meet you all! Could one of you walk me
> through this code?
>    def myThread(*argtuple):
>         """
>         A little thread we've added
>         """
>         print "myThread: entered"
>         q = argtuple[0]
>         print "myThread: starting loop"
>         x = 10
>         while True:
>             time.sleep(10) # time unit is seconds
>             print "myThread x=%d" % x
>             q.put(str(x)) # stick something on message queue
>             wx.WakeUpIdle() # triggers 'idle' handlers
>             x += 10
> It is from David McNab and Alex Tweedly's tutorial on timers and
> threads, which can be found here:
> Among my questions are:
> """ A little thread we've added""" seems to be an isolated string. It
> does not seem to be doing anything there, almost like a comment. Why
> is it there?

That's what some people call a doc string. It is like a comment in
that it helps the user know what the function is for. Notice the
triple quotes. If you were to type "help(myFunction)", it would grab
the functions doc string and display it. You can read up on them here:

> What is argtuple for? how does it work?

This allows the programmer to pass an arbitrarily long argument list
to the function. It took a little digging, but I found it in the docs
(scroll down towards the bottom):

> What is the queue for?
> Thanks!
> -Ben

I haven't messed with queues as yet, but they are one way of dealing
with multiple threads in GUI programming. The idea is to stick
something in the queue for the GUI thread (or potentially some other
thread) to pick up when it's not busy. So one thread sticks something
on the queue and another thread checks the queue periodically to see
if there's something there and if there is, it picks it up. At least,
that's my understanding. You can read up on various methods of messing
with threads in wxPython here:

And here are the queue docs (for 2.6...):

I recommend learning how to use Google effectively. I found about half
the links above using it. You might also find joining the wxPython
mailing list beneficial. I learn a lot there just by reading and
posting to it:

- Mike

More information about the Python-list mailing list