Curses and Threading

Ian Clark iclark at mail.ewu.edu
Tue Jan 22 18:23:59 CET 2008


On 2008-01-22, Brett.Friermood at gmail.com <Brett.Friermood at gmail.com> wrote:
>> In fact you have *two* threads: the main thread, and the one you create
>> explicitly.
>
>> After you start the clock thread, the main thread continues executing,
>> immediately entering the finally clause.
>> If you want to wait for the other thread to finish, use the join() method.
>> But I'm unsure if this is the right way to mix threads and curses.
>
> This is what the python documentation says:
>
> join([timeout])
>     Wait until the thread terminates. This blocks the calling thread
> until the thread whose join() method is called terminates.
>
> So according to this since I need to block the main thread until the
> clock thread ends I would need the main thread to call
> "cadtime().join()", correct? I'm not sure how to do this because I
> don't have a class or anything for the main thread that I know of. I
> tried putting that after cadtime().start() but that doesn't work. I
> guess what I'm trying to say is how can I tell the main thread what to
> do when it doesn't exist in my code?
>
> Thanks for the help
> -Brett

join() is a method on Thread objects. So you'll need a reference to the
Thread you create, then call join() on that.

    thread = cadtime()
	thread.start()
	thread.join()

Ian




More information about the Python-list mailing list