diff --git a/swh/loader/mercurial/hgutil.py b/swh/loader/mercurial/hgutil.py --- a/swh/loader/mercurial/hgutil.py +++ b/swh/loader/mercurial/hgutil.py @@ -2,6 +2,7 @@ # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information + from collections import defaultdict from dataclasses import dataclass import io @@ -154,12 +155,13 @@ if process.is_alive(): process.terminate() - # Give it a second (literally), then kill it + # Give it literally a second (in successive steps of 0.1 second), then kill it. # Can't use `process.join(1)` here, billiard appears to be bugged # https://github.com/celery/billiard/issues/270 killed = False + step = 0.1 for _ in range(10): - time.sleep(0.1) + time.sleep(step) if not process.is_alive(): break else: diff --git a/swh/loader/mercurial/tests/test_hgutil.py b/swh/loader/mercurial/tests/test_hgutil.py --- a/swh/loader/mercurial/tests/test_hgutil.py +++ b/swh/loader/mercurial/tests/test_hgutil.py @@ -16,11 +16,13 @@ src = "https://www.mercurial-scm.org/repo/hello" dest = "/dev/null" timeout = 0.1 + sleepy_time = 100 * timeout + assert sleepy_time > timeout - def clone(*args, **kwargs): + def clone(*args, sleepy_time=sleepy_time, **kwargs): # ignore SIGTERM to force sigkill signal.signal(signal.SIGTERM, lambda signum, frame: None) - time.sleep(2) + time.sleep(sleepy_time) # we make sure we exceed the timeout monkeypatch.setattr(hg, "clone", clone)