<#21243 Running python source restarts on dependen...
# github-notifications
c
#21243 Running python source restarts on dependency change even with `restartable=False` in 2.22.0a0 and newer Issue created by huonw Describe the bug The interrupt/restart behaviour of
pants run path/to/source.py
should depend on the
restartable
flag (https://www.pantsbuild.org/2.22/reference/targets/python_source#restartable): if
False
(default), it runs to completion even if
dependencies
change while it is running. If
True
, pants will interrupt it and restart if
dependencies
change. This appears to have regressed in 2.22.0a0: the script is always restarted when
dependencies
change, no matter the setting of
restartable
. Workaround: run with https://www.pantsbuild.org/2.22/reference/global-options#watch_filesystem :
pants --no-watch-filesystem run ...
Reproducer: • python script with
restartable
left at the default and a dependency on
test.txt
• script appends a line to the
test.txt
file • running with 2.22.0.dev3 (previous release before 2.22.0a0) gives expected behaviour (run to completion) • running with 2.22.0a0 gives an infinite lop cd $(mktemp -d) cat > pants.toml <<EOF [GLOBAL] pants_version = "2.22.0a0" backend_packages = ["pants.backend.python"] [python] interpreter_constraints = ["==3.12.*"] EOF cat > BUILD <<EOF file(name="test", source="test.txt") python_sources(name="src", dependencies=[":test"]) EOF touch test.txt # Script that writes to that dependent file, and then sleeps for a bit # to let pants detect the change: cat > script.py <<EOF import time print("Appending to test...") with open("test.txt", "a") as f: print("line", file=f, flush=True) print("Sleeping...") time.sleep(3) print("Done") EOF # OK: previous version, runs to completion: PANTS_VERSION=2.22.0.dev3 pants run ./script.py # BUG: infinite "KeyboardInterrupt" loop pants run ./script.py Output of `OK`:
Copy code
10:30:23.57 [INFO] Initializing scheduler...
10:30:26.78 [INFO] Scheduler initialized.
Appending to test...
Sleeping...
Done
Output of `BUG`:
Copy code
10:30:37.21 [INFO] Initializing scheduler...
10:30:37.23 [INFO] Initializing Nailgun pool for 16 processes...
10:30:40.40 [INFO] Scheduler initialized.
Appending to test...
Sleeping...
Traceback (most recent call last):
  File "/private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/pants-sandbox-cHCPbo/./.cache/pex_root/venvs/ce5b085030fde446d9c4322baf3898e7ccf0db79/cb65d2da7be9e8f48fdcbf49451aed28d72d6974/pex", line 320, in <module>
    runpy.run_module(module_name, run_name="__main__", alter_sys=True)
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/pants-sandbox-cHCPbo/./script.py", line 8, in <module>
    time.sleep(3)
KeyboardInterrupt
Appending to test...
Sleeping...
Traceback (most recent call last):
  File "/private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/pants-sandbox-BDZBvY/./.cache/pex_root/venvs/ce5b085030fde446d9c4322baf3898e7ccf0db79/cb65d2da7be9e8f48fdcbf49451aed28d72d6974/pex", line 320, in <module>
    runpy.run_module(module_name, run_name="__main__", alter_sys=True)
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/private/var/folders/sv/vd266m4d4lvctgs2wpnhjs9w0000gn/T/pants-sandbox-BDZBvY/./script.py", line 8, in <module>
    time.sleep(3)
KeyboardInterrupt
Appending to test...
...
Pants version 2.22.0a0 OS macOS Additional info Diff of the range of interest: release_2.22.0.dev3...release_2.22.0a0 Not obvious what's the cause (might require a bisect). Maybe: #20874 ??? pantsbuild/pants