Commit 52f5022a authored by Jason Madden's avatar Jason Madden

Convert FileObjectClosend and cancel_wait_ex to classes

Instead of singleton instances. This is because exception objects are
stateful on Python 3, so these singletons could potentially be keeping
lots of extra state around.

greenlet.throw() accepts either an instance or a class so this results
in no extra internal changes.
parent b231c15e
......@@ -32,6 +32,11 @@
under CPython and PyPy. gevent follows the CPython
convention, although these functions cannot be called with
keyword arguments on CPython.
- The previously-singleton exception objects ``FileObjectClosed`` and
``cancel_wait_ex`` were converted to classes. On Python 3, an
exception object is stateful, including references to its context
and possibly traceback, which could lead to objects remaining alive
longer than intended.
1.2.1 (2017-01-12)
==================
......
......@@ -6,8 +6,18 @@ except ImportError:
from io import TextIOWrapper
cancel_wait_ex = IOError(EBADF, 'File descriptor was closed in another greenlet')
FileObjectClosed = IOError(EBADF, 'Bad file descriptor (FileObject was closed)')
class cancel_wait_ex(IOError):
def __init__(self):
super(cancel_wait_ex, self).__init__(
EBADF, 'File descriptor was closed in another greenlet')
class FileObjectClosed(IOError):
def __init__(self):
super(FileObjectClosed, self).__init__(
EBADF, 'Bad file descriptor (FileObject was closed)')
class FileObjectBase(object):
"""
......
......@@ -204,7 +204,11 @@ def wait_readwrite(fileno, timeout=None, timeout_exc=_NONE, event=_NONE):
return wait(io, timeout, timeout_exc)
#: The exception raised by default on a call to :func:`cancel_wait`
cancel_wait_ex = error(EBADF, 'File descriptor was closed in another greenlet') # pylint: disable=undefined-variable
class cancel_wait_ex(error): # pylint: disable=undefined-variable
def __init__(self):
super(cancel_wait_ex, self).__init__(
EBADF,
'File descriptor was closed in another greenlet')
def cancel_wait(watcher, error=cancel_wait_ex):
......
......@@ -175,7 +175,7 @@ class FileObjectThread(FileObjectBase):
# This is different than FileObjectPosix, etc,
# because we want to save the expensive trip through
# the threadpool.
raise FileObjectClosed
raise FileObjectClosed()
with lock:
return threadpool.apply(method, args, kwargs)
......
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