Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1118. Also some speed improvements for semaphores.
- Loading branch information
Showing
22 changed files
with
250 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
# cython: auto_pickle=False | ||
# cython: auto_pickle=False,embedsignature=True,always_allow_keywords=False | ||
from __future__ import print_function, absolute_import, division | ||
import sys | ||
from gevent.hub import get_hub, getcurrent | ||
|
||
from gevent.hub import get_hub | ||
from gevent.timeout import Timeout | ||
|
||
|
||
__all__ = ['Semaphore', 'BoundedSemaphore'] | ||
__all__ = [ | ||
'Semaphore', | ||
'BoundedSemaphore', | ||
] | ||
|
||
# In Cython, we define these as 'cdef inline' functions. The | ||
# compilation unit cannot have a direct assignment to them (import | ||
# is assignment) without generating a 'lvalue is not valid target' | ||
# error. | ||
locals()['getcurrent'] = __import__('greenlet').getcurrent | ||
locals()['greenlet_init'] = lambda: None | ||
|
||
|
||
class Semaphore(object): | ||
|
@@ -101,7 +113,7 @@ def _notify_links(self): | |
try: | ||
link(self) # Must use Cython >= 0.23.4 on PyPy else this leaks memory | ||
except: # pylint:disable=bare-except | ||
getcurrent().handle_error((link, self), *sys.exc_info()) | ||
getcurrent().handle_error((link, self), *sys.exc_info()) # pylint:disable=undefined-variable | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jamadden
Author
Member
|
||
if self._dirty: | ||
# We mutated self._links so we need to start over | ||
break | ||
|
@@ -158,7 +170,7 @@ def _do_wait(self, timeout): | |
elapses, return the exception. Otherwise, return None. | ||
Raises timeout if a different timer expires. | ||
""" | ||
switch = getcurrent().switch | ||
switch = getcurrent().switch # pylint:disable=undefined-variable | ||
self.rawlink(switch) | ||
try: | ||
timer = Timeout._start_new_or_dummy(timeout) | ||
|
@@ -267,4 +279,25 @@ def __init__(self, *args, **kwargs): | |
def release(self): | ||
if self.counter >= self._initial_value: | ||
raise self._OVER_RELEASE_ERROR("Semaphore released too many times") | ||
return Semaphore.release(self) | ||
Semaphore.release(self) | ||
|
||
|
||
def _init(): | ||
greenlet_init() # pylint:disable=undefined-variable | ||
|
||
_init() | ||
|
||
# By building the semaphore with Cython under PyPy, we get | ||
# atomic operations (specifically, exiting/releasing), at the | ||
# cost of some speed (one trivial semaphore micro-benchmark put the pure-python version | ||
# at around 1s and the compiled version at around 4s). Some clever subclassing | ||
# and having only the bare minimum be in cython might help reduce that penalty. | ||
# NOTE: You must use version 0.23.4 or later to avoid a memory leak. | ||
# https://mail.python.org/pipermail/cython-devel/2015-October/004571.html | ||
# However, that's all for naught on up to and including PyPy 4.0.1 which | ||
# have some serious crashing bugs with GC interacting with cython. | ||
# It hasn't been tested since then, and PURE_PYTHON is assumed to be true | ||
# for PyPy in all cases anyway, so this does nothing. | ||
|
||
from gevent._util import import_c_accel | ||
import_c_accel(globals(), 'gevent.__semaphore') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Cython doesn't like this at all.
Same error for python 2.7.14 and 3.6.4
cython 0.27.3
Building from git: