cozos commented on code in PR #26526:
URL: https://github.com/apache/beam/pull/26526#discussion_r1185933893
##########
sdks/python/apache_beam/transforms/core.py:
##########
@@ -2268,19 +2279,35 @@ def finish_bundle(self):
def teardown(self):
self._call_remote(self._remote_teardown)
- self._pool.shutdown()
- self._pool = None
+ self._terminate_pool()
def _call_remote(self, method, *args, **kwargs):
if self._pool is None:
self._pool = concurrent.futures.ProcessPoolExecutor(1)
self._pool.submit(self._remote_init, self._serialized_fn).result()
try:
- return self._pool.submit(method, *args, **kwargs).result()
- except concurrent.futures.process.BrokenProcessPool:
- self._pool = None
+ return self._pool.submit(method, *args, **kwargs).result(
+ self._timeout if method == self._remote_process else None)
+ except (concurrent.futures.process.BrokenProcessPool,
+ TimeoutError,
+ concurrent.futures._base.TimeoutError):
+ self._terminate_pool()
raise
+ def _terminate_pool(self):
+ """Forcibly terminate the pool, not leaving any live subprocesses."""
+ pool = self._pool
+ self._pool = None
+ processes = list(pool._processes.values())
+ pool.shutdown(wait=False)
+ for p in processes:
+ if p.is_alive():
+ p.kill()
+ time.sleep(1)
+ for p in processes:
+ if p.is_alive():
+ p.terminate()
Review Comment:
My understanding is that `SIGTERM` can be intercepted by a program and thus
lets it gracefully die, whereas SIGKILL cannot be intercepted and thus results
in abrupt termination. With that in mind, wouldn't it make sense to terminate,
then kill?
--
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]