File tree 1 file changed +18
-8
lines changed
1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change 12
12
from .backend import TelemetryBackend
13
13
from ..utils .cid import get_or_generate_cid , remove_cid_file
14
14
from ..utils .params import telemetry_params
15
- import multiprocessing
15
+ from platform import system
16
16
17
17
18
18
def _send_func (request_data ):
@@ -70,13 +70,23 @@ def send(self, message: dict):
70
70
else :
71
71
log .info ("Incorrect backend URL." )
72
72
return
73
- process = multiprocessing .Process (target = _send_func , args = (req ,))
74
- process .daemon = True
75
- process .start ()
76
-
77
- process .join (self .timeout )
78
- if process .is_alive ():
79
- process .terminate ()
73
+ if system () == 'Windows' :
74
+ _send_func (req )
75
+ else :
76
+ # request.urlopen() may hang on Linux if there's no internet connection,
77
+ # so we need to run it in a subprocess and terminate after timeout.
78
+
79
+ # Usage of subprocesses on Windows cause unexpected behaviour, when script
80
+ # executes multiple times during subprocess initializing. For this reason
81
+ # subprocess are not recommended on Windows.
82
+ import multiprocessing
83
+ process = multiprocessing .Process (target = _send_func , args = (req ,))
84
+ process .daemon = True
85
+ process .start ()
86
+
87
+ process .join (self .timeout )
88
+ if process .is_alive ():
89
+ process .terminate ()
80
90
81
91
except Exception as err :
82
92
pass # nosec
You can’t perform that action at this time.
0 commit comments