Commit 75283aaf authored by Brandon Carpenter's avatar Brandon Carpenter Committed by Jason Madden

Fix for issues #461 and #471.

This handles None exception values that would otherwise fail when passed
to traceback.print_exception() and prevent the process from exiting. An associated test is also included.
parent c979a25c
......@@ -334,6 +334,11 @@ class Hub(greenlet):
cb.stop()
def print_exception(self, context, type, value, tb):
# Python 3 does not gracefully handle None value or tb in
# traceback.print_exception() as previous versions did.
if value is None:
sys.stderr.write('%s\n' % type.__name__)
else:
traceback.print_exception(type, value, tb)
del tb
if context is not None:
......
'''Test for GitHub issues 461 and 471.
When moving to Python 3, handling of KeyboardInterrupt exceptions caused
by a Ctrl-C raise an exception while printing the traceback for a
greenlet preventing the process from exiting. This test tests for proper
handling of KeyboardInterrupt.
'''
import sys
if sys.argv[1:] == ['subprocess']:
import gevent
def task():
sys.stdout.write('ready\n')
sys.stdout.flush()
gevent.sleep(30)
try:
gevent.spawn(task).get()
except KeyboardInterrupt:
pass
else:
import signal
from subprocess import Popen, PIPE, TimeoutExpired
if sys.platform.startswith('win'):
from subprocess import CREATE_NEW_PROCESS_GROUP
kwargs = {'creationflags': CREATE_NEW_PROCESS_GROUP}
else:
kwargs = {}
p = Popen([sys.executable, __file__, 'subprocess'], stdout=PIPE, **kwargs)
p.stdout.readline()
p.send_signal(signal.SIGINT)
try:
p.wait(3)
except TimeoutExpired:
p.terminate()
sys.exit(1)
sys.exit(p.returncode)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment