1. check out the Caveats for thread module: http://docs.python.org/lib/module-thread.html
Threads interact strangely with interrupts: the KeyboardInterru pt exceptionwill be received by an arbitrary thread. (When the signal module is available, interrupts always go to the main thread.)
i.e., all threads (including main) to catch interrupt exceptions, and propagate that information to other threads.
2. since there is no way to interrupt a sleep (not aware of any), sleep is not the choice. use something else like napping. I mean, take shorter intervals of sleep, check every thing is fine and go back to napping. if something is fishy - go catch it.
hope that helps.
Edwin
-----Original Message-----
From: python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org
[mailto:python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org]
On Behalf Of Rhamphoryncus
Sent: Thursday, August 14, 2008 2:52 PM
To: python-list@python.org
Subject: Re: threading
On Aug 14, 3:30 am, "Mathieu Prevot" <mathieu.pre... @ens.frwrote:
(For some reason the OP hasn't come through to groups.google.c om..
odd)
Note that it won't interrupt any blocked I/O, which is often what you
need the most. If your threads are CPU-bound you can simply have them
check a flag and exit if it becomes True.
--
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
Threads interact strangely with interrupts: the KeyboardInterru pt exceptionwill be received by an arbitrary thread. (When the signal module is available, interrupts always go to the main thread.)
i.e., all threads (including main) to catch interrupt exceptions, and propagate that information to other threads.
2. since there is no way to interrupt a sleep (not aware of any), sleep is not the choice. use something else like napping. I mean, take shorter intervals of sleep, check every thing is fine and go back to napping. if something is fishy - go catch it.
hope that helps.
Edwin
-----Original Message-----
From: python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org
[mailto:python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org]
On Behalf Of Rhamphoryncus
Sent: Thursday, August 14, 2008 2:52 PM
To: python-list@python.org
Subject: Re: threading
On Aug 14, 3:30 am, "Mathieu Prevot" <mathieu.pre... @ens.frwrote:
2008/8/13 Parimala <parimal...@acc ord-soft.com>:
>
>
>
>
>
>
>
>
>
>
>
Hi,
>
a terminate method is given here:http://sebulba.wikispaces.com/recipe+thread2
>
so you can terminate the thread by:
>
(...)
t.start()
(...)
>
while True:
try:
#some code
except KeyboardInterru pt:
t.terminate()
break
>
Mathieu
>
>
>
Hello,
I am using python2.5.1 version to run my test scripts. Iwant to use
'threading' module in my tests. As a startup program, I had run the
following one.
'threading' module in my tests. As a startup program, I had run the
following one.
importthreading
import sys
import time
import sys
import time
def hello():
i=0
try:
while i<10:
print "hi"
time.sleep(1)
i+=1
except KeyboardInterru pt:
print 'KeyboardInterr upt'
raise KeyboardInterru pt
i=0
try:
while i<10:
print "hi"
time.sleep(1)
i+=1
except KeyboardInterru pt:
print 'KeyboardInterr upt'
raise KeyboardInterru pt
try:
thread=threadin g.Thread(target =hello,args=())
thread.start()
except KeyboardInterru pt:
print 'KeyboardInterr upt'
raise KeyboardInterru pt
thread=threadin g.Thread(target =hello,args=())
thread.start()
except KeyboardInterru pt:
print 'KeyboardInterr upt'
raise KeyboardInterru pt
once program starts, problem is..
I am not able to abort the thread using (CTRL+C) KeyboardInterru pt. While
running if I press CTRL+C, it won't generate any exception until the end of
the execution. Once the execution gets over, it will give "Exception
exceptions.Keyb oardInterrupt in <module 'threading' from
'C:\python25\li b\threading.py' ignored" this message and exits.
I am not able to abort the thread using (CTRL+C) KeyboardInterru pt. While
running if I press CTRL+C, it won't generate any exception until the end of
the execution. Once the execution gets over, it will give "Exception
exceptions.Keyb oardInterrupt in <module 'threading' from
'C:\python25\li b\threading.py' ignored" this message and exits.
I had gone through some documents, it says if a thread is joined with
.join() method then we can't stop that process until it releases the lock
what it acquired. But in the above program I didn't use .join() method but
still I am not able to abort the thread.
.join() method then we can't stop that process until it releases the lock
what it acquired. But in the above program I didn't use .join() method but
still I am not able to abort the thread.
Could you please suggest me how can I abort the thread at any point in time
using CTRL+C.
using CTRL+C.
Hi,
>
a terminate method is given here:http://sebulba.wikispaces.com/recipe+thread2
>
so you can terminate the thread by:
>
(...)
t.start()
(...)
>
while True:
try:
#some code
except KeyboardInterru pt:
t.terminate()
break
>
Mathieu
odd)
Note that it won't interrupt any blocked I/O, which is often what you
need the most. If your threads are CPU-bound you can simply have them
check a flag and exit if it becomes True.
--
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.