9
9
REMOTED_PATH = '/usr/libexec/remoted'
10
10
11
11
12
- def _get_remoted_process () -> psutil .Process :
12
+ def get_remoted_process () -> psutil .Process :
13
13
for process in psutil .process_iter ():
14
14
if process .pid == 0 :
15
15
# skip kernel task
@@ -21,24 +21,42 @@ def _get_remoted_process() -> psutil.Process:
21
21
continue
22
22
23
23
24
- @contextlib .contextmanager
25
- def stop_remoted () -> Generator [None , None , None ]:
24
+ def stop_remoted_if_required () -> None :
26
25
if platform .system () != 'Darwin' :
27
26
# only Darwin systems require it
28
- yield
29
27
return
30
28
31
- remoted = _get_remoted_process ()
29
+ remoted = get_remoted_process ()
32
30
if remoted .status () == 'stopped' :
33
31
# process already stopped, we don't need to do anything
34
- yield
35
32
return
36
33
37
34
try :
38
35
remoted .suspend ()
39
36
except psutil .AccessDenied :
40
37
raise AccessDeniedError ()
38
+
39
+
40
+ def resume_remoted_if_required () -> None :
41
+ if platform .system () != 'Darwin' :
42
+ # only Darwin systems require it
43
+ return
44
+
45
+ remoted = get_remoted_process ()
46
+ if remoted .status () == 'running' :
47
+ # process already running, we don't need to do anything
48
+ return
49
+
50
+ try :
51
+ remoted .resume ()
52
+ except psutil .AccessDenied :
53
+ raise AccessDeniedError ()
54
+
55
+
56
+ @contextlib .contextmanager
57
+ def stop_remoted () -> Generator [None , None , None ]:
58
+ stop_remoted_if_required ()
41
59
try :
42
60
yield
43
61
finally :
44
- remoted . resume ()
62
+ resume_remoted_if_required ()
0 commit comments