gifted-soccer-38559
02/02/2022, 1:14 AM./pants run
seems to be interfering with python signal handling in a way that is causing context managers to not get cleaned up -- wondering if there is a workaround for this.
as an example, if i take the following simple script:
from typing import Iterator
from contextlib import contextmanager
import time
@contextmanager
def test_sync_ctx() -> Iterator[None]:
print("[test_sync_ctx] creating...")
time.sleep(1.2)
try:
yield None
finally:
print("[test_sync_ctx] closing...")
time.sleep(1.2)
print("[test_sync_ctx] closed")
def main() -> None:
with test_sync_ctx():
print("inside sync context. sleeping...")
time.sleep(5)
print("slept.")
if __name__ == "__main__":
main()
Running directly with python, i get the following output:
[test_sync_ctx] creating...
inside sync context. sleeping...
^C[test_sync_ctx] closing...
[test_sync_ctx] closed
Traceback (most recent call last):
File "test_ctx.py", line 26, in <module>
main()
File "test_ctx.py", line 21, in main
time.sleep(5)
KeyboardInterrupt
But using pants, no cleanup is ever run. I get the following output:
[test_sync_ctx] creating...
inside sync context. sleeping...
^CInterrupted by user.
happy-kitchen-89482
02/02/2022, 1:27 AMgifted-soccer-38559
02/02/2022, 1:30 AMhappy-kitchen-89482
02/02/2022, 1:33 AMgifted-soccer-38559
02/02/2022, 1:36 AMwitty-crayon-22786
02/02/2022, 4:00 AMhappy-kitchen-89482
02/02/2022, 4:30 AM