diff --git a/unix/__init__.py b/unix/__init__.py index e934dde7961ac5660633b8700ab011bd90e631c3..3d2fd06fb79d9e34f2e03b93034b09cb64c6fcde 100644 --- a/unix/__init__.py +++ b/unix/__init__.py @@ -15,6 +15,24 @@ def hang_until_sig(extra_signals=[]): then also on those signals this call will release.""" global end + # Ascertain what Python are we working on. 2012 PyPy and earlier + # may be affected by https://bugs.pypy.org/issue1255 + + bugged_pypy = False + try: + import platform + except: + pass + else: + if platform.python_implementation() == 'PyPy': + try: + mon, day, year = platform.python_build()[1].split(' ') + year = int(year) + except: + pass + else: + bugged_pypy = year <= 2012 + signal.signal(signal.SIGTERM, __sighandler) signal.signal(signal.SIGINT, __sighandler) for s in extra_signals: @@ -22,7 +40,10 @@ def hang_until_sig(extra_signals=[]): while not end: try: - signal.pause() + if bugged_pypy: + time.sleep(1) # see https://bugs.pypy.org/issue1255 + else: + signal.pause() except: # pause() is undefined on Windows try: # we will sleep for small periods of time time.sleep(0.5)