phoerious commented on a change in pull request #16658:
URL: https://github.com/apache/beam/pull/16658#discussion_r813373631
##########
File path: sdks/python/apache_beam/runners/worker/worker_pool_main.py
##########
@@ -51,6 +51,28 @@
_LOGGER = logging.getLogger(__name__)
+def kill_process_gracefully(proc, timeout=10):
+ """
+ Kill a worker process gracefully by sending a SIGTERM and waiting for
+ it to finish. A SIGKILL will be sent if the process has not finished
+ after ``timeout`` seconds.
+ """
+ def _kill():
+ proc.terminate()
+ t = time.time()
+ while time.time() < t + timeout:
+ time.sleep(0.01)
+ if proc.poll() is not None:
Review comment:
True, but that wouldn't be less code, because it requires a surrounding
try/except block. The docs also suggest that wait with timeout does busy wait,
so doing an explicit while with sleep is probably better anyway.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]