Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83797

Re: How to terminate the function that runs every n seconds

From "Frank Millman" <frank@chagford.com>
Subject Re: How to terminate the function that runs every n seconds
Date 2015-01-15 08:56 +0200
References <CACT3xuWvN=zUs5CmuxceG9yv2gPWkmxF2dTgWOr8WqmaJxag+A@mail.gmail.com> <CACT3xuUr-07yW-FjiKBjPbsbn5j7r1vUfu1E0A6Myz=7sYpnzA@mail.gmail.com> <54B69A5B.5000801@davea.name> <CACT3xuXSuXyRu8ReXLczFw9N_LEajQzDM=eccdU3GPmj4MgYLA@mail.gmail.com> <1j1ebalmgkuskq0ltnv5m4sbm6d3p5f840@4ax.com>
Newsgroups comp.lang.python
Message-ID <mailman.17742.1421304984.18130.python-list@python.org> (permalink)

Show all headers | View raw


"Dennis Lee Bieber" <wlfraed@ix.netcom.com> wrote in message 
news:1j1ebalmgkuskq0ltnv5m4sbm6d3p5f840@4ax.com...
>
> Pseudo (Python 2.x) code
>
> def aThread(delay=600.0): #default 10 minutes
>     while keepRunning:
>         print "thread triggered at %s" % time.time()
>         time.sleep(delay)
>     print "thread was commanded to exit"

I read a variation on this theme some years ago that uses 
event.wait(timeout=delay) to manage the delay.

>From the docs, "block until another thread calls set() to set the flag to 
true, or until the optional timeout occurs."

The benefit is that setting the flag terminates the loop straight away, as 
opposed to waiting for the sleep to finish.

I can show some sample code if anyone is interested.

Frank Millman


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to terminate the function that runs every n seconds "Frank Millman" <frank@chagford.com> - 2015-01-15 08:56 +0200

csiph-web