469,623 Members | 1,380 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

FreeBSD KeyboardInterrupt not captured

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
Jun 27 '08 #1
1 1544
On May 7, 5:00 am, radim.ma...@gmail.com wrote:
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.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Ivan Nestlerode | last post: by
reply views Thread by PantherSE | last post: by
4 posts views Thread by Tamas Nepusz | last post: by
4 posts views Thread by Tony Nelson | last post: by
6 posts views Thread by ruka_at_ | last post: by
2 posts views Thread by Michael Goerz | last post: by
7 posts views Thread by Brendon Costa | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.