diff options
author | Harro van der Klauw <hvdklauw@gmail.com> | 2015-03-23 15:29:26 +0100 |
---|---|---|
committer | Harro van der Klauw <hvdklauw@gmail.com> | 2015-03-23 15:29:26 +0100 |
commit | b7e2b731843347877045a95b85750272071f48da (patch) | |
tree | 038e73be898980cd5bc3470c5c686ebd7031ef51 | |
parent | 94c8c1817bab02f5ca9b2b16329b5873d4594827 (diff) | |
download | timeout-decorator-b7e2b731843347877045a95b85750272071f48da.tar.gz |
Fixed issue with PicklingError causes the timeout to never be reached.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | tests/test_timeout_decorator.py | 12 | ||||
-rw-r--r-- | timeout_decorator/timeout_decorator.py | 11 |
4 files changed, 21 insertions, 7 deletions
@@ -28,6 +28,7 @@ pip-log.txt # Unit test / coverage reports .coverage .tox +.cache nosetests.xml # Translations diff --git a/CHANGES.rst b/CHANGES.rst index dd67619..1fd3175 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,10 @@ Changelog ========= +0.3.1 +----- +- Fixed issue with PicklingError causes the timeout to never be reached. + 0.3.0 ----- diff --git a/tests/test_timeout_decorator.py b/tests/test_timeout_decorator.py index 12d5389..e8e9fbf 100644 --- a/tests/test_timeout_decorator.py +++ b/tests/test_timeout_decorator.py @@ -48,3 +48,15 @@ def test_function_name(use_signals): pass assert func_name.__name__ == 'func_name' + + +def test_timeout_pickle_error(): + """Test that when a pickle error occurs a timeout error is raised.""" + @timeout(seconds=1, use_signals=False) + def f(): + time.sleep(0.1) + class Test(object): + pass + return Test() + with pytest.raises(TimeoutError): + f() diff --git a/timeout_decorator/timeout_decorator.py b/timeout_decorator/timeout_decorator.py index 014abc0..17798e3 100644 --- a/timeout_decorator/timeout_decorator.py +++ b/timeout_decorator/timeout_decorator.py @@ -118,7 +118,6 @@ class _Timeout: True, the "value" property may then be checked for returned data. """ self.__limit = kwargs.pop('timeout', self.__limit) - self.cancel() self.__queue = multiprocessing.Queue(1) args = (self.__queue, self.__function) + args self.__process = multiprocessing.Process(target=_target, @@ -135,17 +134,15 @@ class _Timeout: """Terminate any possible execution of the embedded function.""" if self.__process.is_alive(): self.__process.terminate() - raise TimeoutError() + raise TimeoutError() @property def ready(self): """Read-only property indicating status of "value" property.""" - if self.__queue.full(): - return True - elif not self.__queue.empty(): - return True - elif self.__timeout < time.time(): + if self.__timeout < time.time(): self.cancel() + if self.__queue.full() and not self.__queue.empty(): + return True else: return False |