• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

smartondev / gwbackupy / deb2aa08-a890-4101-ad8b-bbfac3177150

pending completion
deb2aa08-a890-4101-ad8b-bbfac3177150

Pull #40

circleci

Márton Somogyi
changelog
Pull Request #40: #38 kill signals handling

73 of 73 new or added lines in 5 files covered. (100.0%)

535 of 1192 relevant lines covered (44.88%)

0.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.02
/gwbackupy/process_helpers.py
1
from __future__ import annotations
1✔
2

3
import logging
1✔
4
import signal
1✔
5
import threading
1✔
6
import time
1✔
7
from datetime import datetime
1✔
8

9
is_killed_handling: bool = False
1✔
10
is_killed_value: bool = False
1✔
11
is_killed_lock = threading.RLock()
1✔
12

13

14
def is_killed_reset():
1✔
15
    global is_killed_lock
16
    with is_killed_lock:
1✔
17
        global is_killed_value
18
        is_killed_value = False
1✔
19

20

21
def is_killed() -> bool:
1✔
22
    global is_killed_lock
23
    with is_killed_lock:
1✔
24
        global is_killed_handling
25
        if not is_killed_handling:
1✔
26
            signal.signal(signal.SIGINT, is_killed_handling_func)
1✔
27
            signal.signal(signal.SIGTERM, is_killed_handling_func)
1✔
28
            is_killed_handling = True
1✔
29
        global is_killed_value
30
        return is_killed_value
1✔
31

32

33
def is_killed_handling_func(*args):
1✔
34
    global is_killed_lock
35
    with is_killed_lock:
1✔
36
        global is_killed_value
37
        logging.info("Handle kill signal")
1✔
38
        is_killed_value = True
1✔
39

40

41
def sleep_with_check(seconds: float, sleep_step: float = 0.1) -> bool:
1✔
42
    start = datetime.now().timestamp()
1✔
43
    while datetime.now().timestamp() - start < seconds:
1✔
44
        time.sleep(sleep_step)
1✔
45
        if is_killed():
1✔
46
            return False
1✔
47
    return True
1✔
48

49

50
def await_all_futures(futures: [], sleep_step: float = 0.1) -> bool:
1✔
51
    while not is_killed():
1✔
52
        if not sleep_with_check(1, sleep_step=sleep_step):
1✔
53
            return False
1✔
54
        has_not_done = False
1✔
55
        for f in futures:
1✔
56
            if not f.done():
1✔
57
                has_not_done = True
×
58
                break
×
59
        if has_not_done:
1✔
60
            continue
×
61
        else:
62
            break
1✔
63
    return not is_killed()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc