run function in background?

Damian Menscher menscher+python at uiuc.edu
Fri Jun 8 17:26:28 EDT 2001


Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>> Damian Menscher <menscher+python at uiuc.edu> (DM) writes:

> DM> Is there a way to run a function in python in the background?
> DM> Ideally I'd want something like

> DM> def my_func(params):
> DM> 	stuff here

> DM> for i in range(10):
> DM> 	print "starting a process"
> DM> 	my_func(params) &

> DM> where the & indicates that shouldn't stop the flow of the program,
> DM> so the loop would continue and have all 10 go simultaneously.

> Use threads.

Thanks for the response.  That worked (though it took me a while to
figure out how to use threads).

Thanks also to Fellowship CRC, whose response was perfect, but about
30 minutes too late.  I'll quote it here for anyone else interested:

import thread

def my_func(params):
    print params

for i in range(10):
    print "starting a process",i
    thread.start_new_thread(my_func,(i,))


Damian Menscher
-- 
--==## Grad. student & Sys. Admin. @ U. Illinois at Urbana-Champaign ##==--
--==## <menscher at uiuc.edu> www.uiuc.edu/~menscher/ Ofc:(217)333-0038 ##==--
--==## Physics Dept, 1110 W Green, Urbana IL 61801 Fax:(217)333-9819 ##==--



More information about the Python-list mailing list