FreeBSD KeyboardInterrupt not captured

R

radim.marek

Hi Guys,

during testing of my project on FreeBSD I've discovered stange
'feature' of time.sleep(). It works if single thread is running, but
when multi-threaded, the SIGINT signal seems not to be handled in same
way.

I've found three discussion about similar behavior with os.system()
but so far none of the suggested patches worked.

I've limited test to following code:

import time
import sys
import threading

class MyThread(threading.Thread):
def __init__(self):
super(MyThread, self).__init__()
self.start()

def run(self):
while True:
try:
time.sleep(10)
except KeyboardInterrupt:
print 'thread keyboard interrupt'

def main():
my = MyThread()

while True:
try:
time.sleep(5)
except KeyboardInterrupt:
print 'got it'

if __name__ == '__main__':
main()


Any suggestions?

Best regards,

Radim
 
R

Rhamphoryncus

Hi Guys,

during testing of my project on FreeBSD I've discovered stange
'feature' of time.sleep(). It works if single thread is running, but
when multi-threaded, the SIGINT signal seems not to be handled in same
way.

I've found three discussion about similar behavior with os.system()
but so far none of the suggested patches worked.

I've limited test to following code:

import time
import sys
import threading

class MyThread(threading.Thread):
def __init__(self):
super(MyThread, self).__init__()
self.start()

def run(self):
while True:
try:
time.sleep(10)
except KeyboardInterrupt:
print 'thread keyboard interrupt'

def main():
my = MyThread()

while True:
try:
time.sleep(5)
except KeyboardInterrupt:
print 'got it'

if __name__ == '__main__':
main()

Any suggestions?

Python doesn't support interrupting non-main threads with a signal.
You have to use something else you can manually end, like a Condition
with a timeout or a poll of a fd with a timeout.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top