`./pants run` seems to be interfering with python ...
# general
g
./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:
Copy code
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:
Copy code
[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:
Copy code
[test_sync_ctx] creating...
inside sync context. sleeping...
^CInterrupted by user.
๐Ÿ‘€ 2
h
Thanks for reporting! Would you mind opening an issue at https://github.com/pantsbuild/pants/issues/new/choose ? That way we can preserve the info (and eventual solution) for posterity. Thanks!
๐Ÿ‘ 1
g
for sure!
h
But also good that you mentioned it here so we know to pay attention ๐Ÿ™‚
g
looks like it is related to this issue, do you think this is duplicate or should i still create a new one?
w
i think youโ€™re right. bumping that one would be appreciated.
h
Yeah, that seems correct. But adding your example repro to that ticket would be super helpful!
๐Ÿ‘ 1