You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, thanks for your effort in developing and maintaining this very good library. It is very helpful for me to use it with asyncio.
I found one strange behavior but not sure whether it could be considered as a bug. If you run the following code in a python file, the main process where the event loop run get SIGTERM signal after the cancellation of a running future. This is fine if the main process just ignore it, however, for my real code running in K8S, the SIGTERM signal is handled in main process for graceful shutdown in case of pod scaling down. Therefore, the cancellation of a future causing graceful shutdown is not really what I want.
Could you have a look at the code and see whether this is a bug? If it is not, do you have any suggestion about how could I avoid receiving SIGTERM in main process in case of cancelling running future. Thanks a lot.
importasyncioimporttimefromfunctoolsimportpartialimportsignalfrompebbleimportProcessPooldefcpu_bound_task():
print(f"CPU task started")
time.sleep(30)
print(f"CPU task completed")
asyncdefcancel_future(future):
print('cancel future')
# to give the cpu task a chance to startawaitasyncio.sleep(5)
cancel_result=future.cancel(msg='cancel future due to OOM')
print(f"done cancel: {cancel_result}")
asyncdefmain():
pool=ProcessPool(max_workers=2)
loop=asyncio.get_running_loop()
loop.add_signal_handler(
signal.SIGTERM,
lambda: print("SIGTERM received")
)
func_in_executor=partial(cpu_bound_task)
result_future=loop.run_in_executor(pool, func_in_executor, 0)
try:
results=awaitasyncio.gather(
cancel_future(result_future),
result_future,
# return_exceptions=True
)
forresinresults:
print(res, type(res))
exceptasyncio.CancelledError:
print('gather is cancelled')
awaitasyncio.sleep(30)
print("done sleep in main")
if__name__=="__main__":
asyncio.run(main())
The text was updated successfully, but these errors were encountered:
Hi, thanks for your effort in developing and maintaining this very good library. It is very helpful for me to use it with
asyncio
.I found one strange behavior but not sure whether it could be considered as a bug. If you run the following code in a python file, the main process where the event loop run get
SIGTERM
signal after the cancellation of a running future. This is fine if the main process just ignore it, however, for my real code running in K8S, theSIGTERM
signal is handled in main process for graceful shutdown in case of pod scaling down. Therefore, the cancellation of a future causing graceful shutdown is not really what I want.Could you have a look at the code and see whether this is a bug? If it is not, do you have any suggestion about how could I avoid receiving
SIGTERM
in main process in case of cancelling running future. Thanks a lot.The text was updated successfully, but these errors were encountered: