From 5a6187122dc61a8d4469e1cc5a36f08ef688af44 Mon Sep 17 00:00:00 2001 From: Tim Savannah Date: Wed, 24 May 2017 01:22:17 -0400 Subject: [PATCH] Force cleanup of thread if function completes in time. On python2 this forces the thread to be cleaned up right-away, on python3 it would get cleaned up during the next garbage-collect cycle. In python2 it may take several rounds. --- func_timeout/dafunc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/func_timeout/dafunc.py b/func_timeout/dafunc.py index 03d2b23..4e9dbb5 100644 --- a/func_timeout/dafunc.py +++ b/func_timeout/dafunc.py @@ -84,6 +84,10 @@ def func_timeout(timeout, func, args=(), kwargs=None): thread._stopThread(stopException) thread.join(min(.1, timeout / 50.0)) raise FunctionTimedOut('', timeout, func, args, kwargs) + else: + # We can still cleanup the thread here.. + # Still give a timeout... just... cuz.. + thread.join(.5) if exception: raise exception[0]