Skip to content
Snippets Groups Projects
Commit 987a01fa authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

fix

parent 3fd9ab0c
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ class CallableGroup(object):
@typed(None, Callable, bool)
def add(self, callable, oneshot=False):
"""
:param callable: callable
:param oneshot: if True, callable will be unregistered after single call
"""
self.callables.append((callable, oneshot))
......
......@@ -86,7 +86,7 @@ class CSNotGivenError(CSTypeError):
class CSMultipleValuesGivenError(CSTypeError):
def __str__(self):
return 'Got multiple values for argument' % (self.arg.name,)
return 'Got multiple values for argument %s' % (self.arg.name,)
class CallSignature(object):
......
......@@ -42,15 +42,20 @@ class GenerationPolicy(object):
"""
def __init__(self, enable_pickling=True, compress_at=128 * 1024,
repr_length_limit=128 * 1024):
repr_length_limit=128 * 1024,
compression_level=6):
"""
:param enable_pickling: bool, whether to enable pickling at all
:param compress_at: pickles longer than this (bytes) will be compressed
:param repr_length_limit: maximum length of __repr__. None for no limit.
:param compression_level: "1" is fastest, "9" is slowest
"""
assert isinstance(compression_level, int) and 1 <= compression_level <= 9
self.enable_pickling = enable_pickling
self.compress_at = compress_at
self.repr_length_limit = repr_length_limit
self.compression_level = compression_level
def should_pickle(self, value):
"""
......@@ -76,7 +81,7 @@ class GenerationPolicy(object):
:return: int, 1-9, where "1" is the fastest, and "9" is the slowest,
but produces best compression
"""
return 6
return self.compression_level
def process_repr(self, r):
"""
......
......@@ -71,7 +71,7 @@ class AcquirePIDLock(object):
pid = int(flock.read())
except ValueError:
logger.warning(
'PID file found but does not contain an int, pretending it did not exist')
'PID file found but doesn''t have an int, skipping')
return
except IOError as e:
raise FailedToAcquire()
......
......@@ -6,6 +6,7 @@ from __future__ import print_function, absolute_import, division
import logging
import signal
import sys
import time
from satella.coding import typed
......@@ -14,17 +15,16 @@ logger = logging.getLogger(__name__)
end = False
def __sighandler(a, b):
global end
end = True
@typed(list)
def hang_until_sig(extra_signals=[]):
@typed((list, None))
def hang_until_sig(extra_signals=None):
"""Will hang until this process receives SIGTERM or SIGINT.
If you pass extra signal IDs (signal.SIG*) with extra_signals,
then also on those signals this call will release."""
extra_signals = extra_signals or []
global end
# Ascertain what Python are we working on. 2012 PyPy and earlier
......@@ -33,18 +33,20 @@ def hang_until_sig(extra_signals=[]):
bugged_pypy = False
try:
import platform
except:
except ImportError:
pass
else:
if platform.python_implementation() == 'PyPy':
try:
mon, day, year = platform.python_build()[1].split(' ')
year = int(year)
except:
except (TypeError, ValueError):
pass
else:
bugged_pypy = year <= 2012
sleep = lambda: time.sleep(1) if bugged_pypy else signal.pause
signal.signal(signal.SIGTERM, __sighandler)
signal.signal(signal.SIGINT, __sighandler)
for s in extra_signals:
......@@ -52,11 +54,8 @@ def hang_until_sig(extra_signals=[]):
while not end:
try:
if bugged_pypy:
time.sleep(1) # see https://bugs.pypy.org/issue1255
else:
signal.pause()
except: # pause() is undefined on Windows
sleep()
except AttributeError: # pause() is undefined on Windows
try: # we will sleep for small periods of time
time.sleep(0.5)
except IOError: # "Interrupted system call"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment