https://pantsbuild.org/ logo
#general
Title
# general
g

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:
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

happy-kitchen-89482

02/02/2022, 1:27 AM
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

gifted-soccer-38559

02/02/2022, 1:30 AM
for sure!
h

happy-kitchen-89482

02/02/2022, 1:33 AM
But also good that you mentioned it here so we know to pay attention ๐Ÿ™‚
g

gifted-soccer-38559

02/02/2022, 1:36 AM
looks like it is related to this issue, do you think this is duplicate or should i still create a new one?
w

witty-crayon-22786

02/02/2022, 4:00 AM
i think youโ€™re right. bumping that one would be appreciated.
h

happy-kitchen-89482

02/02/2022, 4:30 AM
Yeah, that seems correct. But adding your example repro to that ticket would be super helpful!
๐Ÿ‘ 1
4 Views