Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83785
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; '(python': 0.07; 'assignment': 0.07; '%s"': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:How': 0.10; 'def': 0.12; 'jan': 0.12; 'thread': 0.14; 'message-id:@4ax.com': 0.16; 'quit.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subroutine': 0.16; 'summary,': 0.16; 'time.time()': 0.16; 'wed,': 0.18; 'print': 0.22; 'url:home': 0.24; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'statement': 0.30; 'code': 0.31; 'subject:that': 0.31; 'terminate': 0.31; 'run': 0.32; 'bugs': 0.33; 'subject:the': 0.34; 'something': 0.35; 'false': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'half': 0.37; 'needed': 0.38; 'to:addr:python-list': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'signal': 0.60; 'tell': 0.60; 'skip:t 30': 0.61; 'telling': 0.64; 'total': 0.65; 'minutes': 0.67; '2015': 0.84; 'commanded': 0.84; 'received:108': 0.93 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: How to terminate the function that runs every n seconds |
| Date | Wed, 14 Jan 2015 19:35:29 -0500 |
| Organization | IISS Elusive Unicorn |
| References | <CACT3xuWvN=zUs5CmuxceG9yv2gPWkmxF2dTgWOr8WqmaJxag+A@mail.gmail.com> <CACT3xuUr-07yW-FjiKBjPbsbn5j7r1vUfu1E0A6Myz=7sYpnzA@mail.gmail.com> <54B69A5B.5000801@davea.name> <CACT3xuXSuXyRu8ReXLczFw9N_LEajQzDM=eccdU3GPmj4MgYLA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-108-79-218-84.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17737.1421283049.18130.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1421283049 news.xs4all.nl 2839 [2001:888:2000:d::a6]:38082 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:83785 |
Show key headers only | View raw
On Wed, 14 Jan 2015 22:56:11 +0530, Ganesh Pal <ganesh1pal@gmail.com>
declaimed the following:
>
> My assignment was to write a subroutine that run itself every n
>minutes and terminate before the main thread completes.
>
Unless something is missing in that summary, no thread is needed either
-- just a function with a loop around a delay statement of some sort.
However, on the basis that you are required to be dumping a message at
periodic intervals in parallel with something from the main thread AND that
the main thread has to tell the subthread when it should exit... 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"
theThread = threading.Thread(target=aThreading, kwargs={delay:30.0})
# half minute
keepRunning = True
theThread.start()
for x in range(5):
print "main loop at %s" % time.time()
time.sleep(60.0) # one minute, with loop total 5 minutes
keepRunning = False
theThread.join()
{There are a few bugs in the above just to make it interesting}
The main thing to consider is that "killing" a thread doesn't work well
in Python. Instead the thread has to check for some signal telling it to
quit.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: How to terminate the function that runs every n seconds Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-01-14 19:35 -0500
Re: How to terminate the function that runs every n seconds Marko Rauhamaa <marko@pacujo.net> - 2015-01-15 11:34 +0200
Re: How to terminate the function that runs every n seconds Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-01-15 09:11 -0500
Re: How to terminate the function that runs every n seconds Marko Rauhamaa <marko@pacujo.net> - 2015-01-15 16:15 +0200
Re: How to terminate the function that runs every n seconds Marko Rauhamaa <marko@pacujo.net> - 2015-01-15 17:29 +0200
csiph-web