kojid: fix restartHosts on py 3.5+
Related: https://pagure.io/koji/issue/3442
This commit is contained in:
parent
1c4f078a08
commit
22b781ad58
2 changed files with 11 additions and 3 deletions
|
|
@ -434,7 +434,13 @@ class BaseTaskHandler(object):
|
|||
remain = start + timeout - time.time()
|
||||
if remain > 0:
|
||||
self.logger.debug("Sleeping for %.1fs", remain)
|
||||
time.sleep(remain)
|
||||
if hasattr(signal, 'sigtimedwait'):
|
||||
# Note, that sigtimedwait doesn't trigger signal handler (from 3.3)
|
||||
signal.sigtimedwait([signal.SIGUSR2], timeout)
|
||||
else:
|
||||
# time.sleep is not interruptible anymore from python 3.5
|
||||
# https://peps.python.org/pep-0475/
|
||||
time.sleep(remain)
|
||||
# check if we're timed out
|
||||
duration = time.time() - start
|
||||
if duration > timeout:
|
||||
|
|
|
|||
|
|
@ -321,8 +321,9 @@ class TasksTestCase(unittest.TestCase):
|
|||
|
||||
@patch('time.time')
|
||||
@patch('time.sleep')
|
||||
@patch('signal.sigtimedwait')
|
||||
@patch('signal.pause')
|
||||
def test_BaseTaskHandler_wait_timeout(self, pause, sleep, time):
|
||||
def test_BaseTaskHandler_wait_timeout(self, pause, sigtimedwait, sleep, time):
|
||||
"""Tests timeout behavior in the wait function"""
|
||||
temp_path = get_tmp_dir_path('TaskTest')
|
||||
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
||||
|
|
@ -342,8 +343,9 @@ class TasksTestCase(unittest.TestCase):
|
|||
|
||||
@patch('time.time')
|
||||
@patch('time.sleep')
|
||||
@patch('signal.sigtimedwait')
|
||||
@patch('signal.pause')
|
||||
def test_BaseTaskHandler_wait_avoid_timeout(self, pause, sleep, time):
|
||||
def test_BaseTaskHandler_wait_avoid_timeout(self, pause, sigtimedwait, sleep, time):
|
||||
"""Tests that timeout does not happen if tasks finish in time"""
|
||||
temp_path = get_tmp_dir_path('TaskTest')
|
||||
obj = TaskTest(95, 'some_method', ['random_arg'], None, None, temp_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue