Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83751 > unrolled thread
| Started by | Ganesh Pal <ganesh1pal@gmail.com> |
|---|---|
| First post | 2015-01-14 18:54 +0530 |
| Last post | 2015-01-14 18:54 +0530 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to terminate the function that runs every n seconds Ganesh Pal <ganesh1pal@gmail.com> - 2015-01-14 18:54 +0530
| From | Ganesh Pal <ganesh1pal@gmail.com> |
|---|---|
| Date | 2015-01-14 18:54 +0530 |
| Subject | Re: How to terminate the function that runs every n seconds |
| Message-ID | <mailman.17718.1421241880.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web