Commit 6da6e6fd authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1299 from gevent/issue1295

Be more careful handling NOT_ERROR during interpreter shutdown.
parents 8181ce31 8b6f95cf
......@@ -28,6 +28,9 @@
``AsyncEvent``. Note that the order in which semaphore links are
called is not specified. See :issue:`1287`, reported by Dan Milon.
- Improve safety of handling exceptions during interpreter shutdown.
See :issue:`1295` reported by BobDenar1212.
1.3.7 (2018-10-12)
==================
......
......@@ -137,7 +137,11 @@ class AbstractCallbacks(object):
# Depending on when the exception happened, the watcher
# may or may not have been stopped. We need to make sure its
# memory stays valid so we can stop it at the ev level if needed.
the_watcher.loop._keepaliveset.add(the_watcher)
# If its loop is gone, it has already been stopped,
# see https://github.com/gevent/gevent/issues/1295 for a case where
# that happened
if the_watcher.loop is not None:
the_watcher.loop._keepaliveset.add(the_watcher)
return -1
else:
if (the_watcher.loop is not None
......
......@@ -511,7 +511,9 @@ class Hub(WaitOperationsGreenlet):
# Unwrap any FileObjectThread we have thrown around sys.stderr
# (because it can't be used in the hub). Tricky because we are
# called in error situations when it's not safe to import.
stderr = sys.stderr
# Be careful not to access sys if we're in the process of interpreter
# shutdown.
stderr = sys.stderr if sys else None # pylint:disable=using-constant-test
if type(stderr).__name__ == 'FileObjectThread':
stderr = stderr.io # pylint:disable=no-member
return stderr
......@@ -521,6 +523,12 @@ class Hub(WaitOperationsGreenlet):
# traceback.print_exception() as previous versions did.
# pylint:disable=no-member
errstream = self.exception_stream
if not errstream: # pragma: no cover
# If the error stream is gone, such as when the sys dict
# gets cleared during interpreter shutdown,
# don't cause follow-on errors.
# See https://github.com/gevent/gevent/issues/1295
return
if value is None:
errstream.write('%s\n' % type.__name__)
......
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