[Tutor] Stopping function after given time

Johan Geldenhuys johan at accesstel.co.za
Mon Oct 10 16:45:44 CEST 2005


You can use the Timer in threading. Look at what is done in the attached 
script. You can basically use three functions to start the timer, stop 
the timer and do what ever it is to be done upon expiring.

There maybe easier ways, but this will work. You can call the 
start_timer with a time in seconds and then it will terminate and there 
you can call a different function that does the rest of your stuff.

Johan.

Raduz wrote:

>Hi all
>Simple question: Is it possible to stop a running function after certain 
>predefined time? 
>
>Right now I have some home-made bash scripts for recording shows from net 
>broadcasted ogg stream, that use wget for stream downloading, and two "at" 
>jobs - one for first script (which prepares directory it's going to save to, 
>dumps info about it's own PID, and execs wget for actual download), second for 
>another script (which reads PID info dumped by the first script, uses it to 
>kill wget and performs some clean-up tasks). 
>I would like to convert this routine to Python using pycurl module, or maybe 
>even standard urllib.urlretrieve. Problem is, downloaded file is a stream 
>without end, so I have to stop the downloader manually, and I would prefer to 
>drop the "two scripts" approach - no more PID saving and process killing. I 
>want one clean package, which will start the download, let it run for some 
>time, and then stop it correctly. I just don't know how to time the download. 
>Can anybody give some sugestions, please? Is the threading way to go? Thanks.
>
>  
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: timertest.py
Type: text/x-python
Size: 3206 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20051010/6114888a/timertest.py


More information about the Tutor mailing list