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


Groups > comp.lang.python > #83751

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

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 <ganesh1pal@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'modified': 0.07; 'executed': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'jan': 0.12; '2.7': 0.14; 'typos': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'import': 0.22; 'to:name :python-list@python.org': 0.22; 'print': 0.22; '(a)': 0.24; 'looks': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'subject:that': 0.31; 'linux': 0.33; 'running': 0.33; 'subject:the': 0.34; 'received:google.com': 0.35; '14,': 0.36; 'module.': 0.36; "didn't": 0.36; 'seconds': 0.37; 'same.': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; '2015': 0.84; 'played': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=myAAcNGWu/iyvjLr25KAHtwh+BZrBvwKK4PwunUiVEM=; b=ON3f+EHCRVnmak6BC8rO8XgfZPFTsvibWedRPyZRDChPxMSd/auJFoB2STh2IFU10j Cvtp9U1Qa3vkQkck5I8NeFUD0ommmqfIWmWAoX1V6HYJa4IC2BPQ75Hj9NDUSvReOhcg +qiASL4zlw10Exv8VVWsUGUKqtPG2oKh0GxkYU9txzvNY7aoSraDsWal4uIRatzhxzrQ NvtdO8iK36OfK7xKuFzfHzb7flsdjqLNwdFfD0DqUiFQ3sjMhBl7+V6wXIPt9N1zjg9A /XziJRpj6xkr6+6EN8yRj5pCO12Ut5c143938eTYYTgd2BHr948mphqD5kyc5PFaDpYp a0Cg==
MIME-Version 1.0
X-Received by 10.152.87.46 with SMTP id u14mr3975354laz.36.1421241878216; Wed, 14 Jan 2015 05:24:38 -0800 (PST)
In-Reply-To <CACT3xuUr-07yW-FjiKBjPbsbn5j7r1vUfu1E0A6Myz=7sYpnzA@mail.gmail.com>
References <CACT3xuWvN=zUs5CmuxceG9yv2gPWkmxF2dTgWOr8WqmaJxag+A@mail.gmail.com> <CACT3xuUr-07yW-FjiKBjPbsbn5j7r1vUfu1E0A6Myz=7sYpnzA@mail.gmail.com>
Date Wed, 14 Jan 2015 18:54:38 +0530
Subject Re: How to terminate the function that runs every n seconds
From Ganesh Pal <ganesh1pal@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.17718.1421241880.18130.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421241880 news.xs4all.nl 2933 [2001:888:2000:d::a6]:47918
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83751

Show key headers only | View raw


I quick modified the code and it now looks like this ,is this ok for
termination ? I played with t.canel() it didn't work

import threading
import time
def printit():
        print "EXECUTED SLEEP"

t = threading.Timer(4, printit)
t.start()
printit()
print "hello"

output :

Throttling-1# python  file_02.py
EXECUTED SLEEP
hello
EXECUTED SLEEP



On Wed, Jan 14, 2015 at 6:39 PM, Ganesh Pal <ganesh1pal@gmail.com> wrote:
> Corrected Typos .
>
>>a) How to I prevent the execution  of   Print "EXECUTED SLEEP" after 4
>> seconds ? , current this is running in an infinite loop
>
>
> On Wed, Jan 14, 2015 at 6:37 PM, Ganesh Pal <ganesh1pal@gmail.com> wrote:
>> Iam using Linux and  Python 2.7  and playing with the threading.Timer module.
>>
>> I had the below question on the same.
>>
>> (a) How to I prevent the execution  the  "EXECUTED SLEEP" after 4
>> seconds ? , current this is running in an infinite loop
>>
>> node-1# cat  file_01.py
>>
>> import threading
>> import time
>> def printit():
>>         threading.Timer(2, printit).start()
>>         print "EXECUTED SLEEP"
>> printit()
>> print "hi"
>> time.sleep(4)
>> print "hi"
>> time.sleep(5)
>>
>> Output:
>> node-1# python  file_01.py
>> EXECUTED SLEEP
>> hi
>> EXECUTED SLEEP
>> EXECUTED SLEEP
>> EXECUTED SLEEP
>>
>>
>>
>> Regards,
>> Ganesh

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


Thread

Re: How to terminate the function that runs every n seconds Ganesh Pal <ganesh1pal@gmail.com> - 2015-01-14 18:54 +0530

csiph-web