Skip to content

Commit 8dcaa7a

Browse files
authored
Use subprocess on Linux only. (openvinotoolkit#68)
* Use subprocess on Linux only. * Minor correction.
1 parent 3e86fe3 commit 8dcaa7a

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/backend/backend_ga4.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .backend import TelemetryBackend
1313
from ..utils.cid import get_or_generate_cid, remove_cid_file
1414
from ..utils.params import telemetry_params
15-
import multiprocessing
15+
from platform import system
1616

1717

1818
def _send_func(request_data):
@@ -70,13 +70,23 @@ def send(self, message: dict):
7070
else:
7171
log.info("Incorrect backend URL.")
7272
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 behavior, 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()
8090

8191
except Exception as err:
8292
pass # nosec

0 commit comments

Comments
 (0)