how to start a new thread from a GUI

chris liechti cliechti at mails.ch
Thu Aug 16 05:21:01 CEST 2001


[posted and mailed]

Wen Jiang <wj691781 at bcm.tmc.edu> wrote in
news:3B7B4D56.81E84D37 at bcm.tmc.edu: 
>> os.spawnv(os.P_NOWAIT, cmd, argv) might work for you.
> 
> The job is a class method in python, not a standalone program,
> os.spawnv might not work with this situation. is it still doable with
> other techniques (fork, thread ?)

the module threading gives an easy to use interface for threads.

t = threading.Thread( target=bgjob_fu, args=("arguments",) )
t.start()

you can't "exit" the gui by terminating python but you can close all
windows and free memory by deleting unused objects with "del" and then 
after all that use

t.join()

to wait for the background job to finish.


-- 
chris <cliechti at mails.ch>




More information about the Python-list mailing list