aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick <pnpnpn@users.noreply.github.com>2015-03-24 14:41:40 -0400
committerPatrick <pnpnpn@users.noreply.github.com>2015-03-24 14:41:40 -0400
commit6e27c8ddf6ee2a74bf6a166be200023bc6f238b0 (patch)
tree54a1fa1f8bb6677e417f143563a47fe458cedb6e
parent94c8c1817bab02f5ca9b2b16329b5873d4594827 (diff)
parent1a765a70b00c3778520d0f7be2a24ce3b1d7873d (diff)
downloadtimeout-decorator-6e27c8ddf6ee2a74bf6a166be200023bc6f238b0.tar.gz
Merge pull request #18 from hvdklauw/multithreading-pickle
Fixed issue with PicklingError causes the timeout to never be reached.
-rw-r--r--.gitignore1
-rw-r--r--CHANGES.rst4
-rw-r--r--setup.py2
-rw-r--r--tests/test_timeout_decorator.py13
-rw-r--r--timeout_decorator/timeout_decorator.py12
5 files changed, 22 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index 280c69c..c0ffae1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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/setup.py b/setup.py
index f5d59ad..5913846 100644
--- a/setup.py
+++ b/setup.py
@@ -27,7 +27,7 @@ long_description = (
setup(
name='timeout-decorator',
- version='0.3.0',
+ version='0.3.1',
description='Timeout decorator',
long_description=long_description,
author='Patrick Ng',
diff --git a/tests/test_timeout_decorator.py b/tests/test_timeout_decorator.py
index 12d5389..f56eb01 100644
--- a/tests/test_timeout_decorator.py
+++ b/tests/test_timeout_decorator.py
@@ -48,3 +48,16 @@ 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..3639b45 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,19 +134,14 @@ 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()
- else:
- return False
+ return self.__queue.full() and not self.__queue.empty()
@property
def value(self):