jolly-midnight-72759
10/14/2020, 5:54 PMpants jupyter
. Before I tackle merging digests or pex files, I wanted to get the exit code correct.
When I run the notebook app then exit with CTRL-C CTRL-C, which is the normal procedure with this version of Jupyter Notebook (i.e. $? = 0
), pantsd
is killed and the whole thing exits with a exit code 1
.
How can I send Jupyter Notebook a CTRL-C without it causing pantsd
to be killed?jolly-midnight-72759
10/14/2020, 5:54 PM[I 09:53:25.043 NotebookApp] Saving file at /Untitled.ipynb
^C09:53:30.02 [INFO] Sending SIGINT to pantsd with pid 24967, waiting up to 5.0 seconds before sending SIGKILL...
[C 09:53:30.031 NotebookApp] received signal 15, stopping
[I 09:53:30.032 NotebookApp] Shutting down kernels
Interrupted by user:
Sending user interrupt to pantsd
[I 09:53:30.236 NotebookApp] Kernel shutdown: 58afed28-9a93-4a6e-98ef-6d7d10000e9f
hundreds-father-404
10/14/2020, 5:55 PMjolly-midnight-72759
10/14/2020, 5:55 PMpants jupyter
so the pex doesn't have an entry point. This drops me into the python repl. When I just do a CTRL-D there, it also errors out.jolly-midnight-72759
10/14/2020, 5:55 PMrc0
.jolly-midnight-72759
10/14/2020, 5:56 PMjolly-midnight-72759
10/14/2020, 5:56 PM% ./pants jupyter cb/chartbeat (CICD-8/pants-v2 :zap:) ip-10-6-1-238
13:55:51.31 [INFO] Pex(digest=<pants.engine.internals.native_engine.PyDigest object at 0x10c95c768>, name='jupyter-py3.pex', python=PythonExecutable(path='/Users/myaccount.g/.pyenv/versions/3.6.9/bin/python3.6', fingerprint='3ecacfd795a12540475b4d0d51c424f73dc8b76f76d357e4dd6a91465c7d8ff1'))
Python 3.6.9 (default, Sep 25 2020, 14:09:40)
[GCC Apple LLVM 12.0.0 (clang-1200.0.32.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
now exiting InteractiveConsole...
13:55:55.01 [INFO] exit code is 0
13:55:55.02 [ERROR] Exception caught: (pants.engine.internals.scheduler.ExecutionError)
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/bin/local_pants_runner.py", line 281, in run
engine_result = self._run_v2()
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/bin/local_pants_runner.py", line 193, in _run_v2
return self._maybe_run_v2_body(goals, poll=False)
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/bin/local_pants_runner.py", line 215, in _maybe_run_v2_body
poll_delay=(0.1 if poll else None),
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/init/engine_initializer.py", line 127, in run_goal_rules
goal_product, params, poll=poll, poll_delay=poll_delay
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/engine/internals/scheduler.py", line 569, in run_goal_rule
self._raise_on_error([t for _, t in throws])
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/engine/internals/scheduler.py", line 533, in _raise_on_error
wrapped_exceptions=tuple(t.exc for t in throws),
Exception message: 1 Exception encountered:
Engine traceback:
in select
in jupyter.goal.jupyter
Traceback (no traceback):
<pants native internals>
Exception: jupyter.goal:27:jupyter() returned a result value that did not satisfy its constraints: <class 'jupyter.goal.Jupyter'>
Traceback (most recent call last):
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/bin/local_pants_runner.py", line 281, in run
engine_result = self._run_v2()
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/bin/local_pants_runner.py", line 193, in _run_v2
return self._maybe_run_v2_body(goals, poll=False)
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/bin/local_pants_runner.py", line 215, in _maybe_run_v2_body
poll_delay=(0.1 if poll else None),
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/init/engine_initializer.py", line 127, in run_goal_rules
goal_product, params, poll=poll, poll_delay=poll_delay
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/engine/internals/scheduler.py", line 569, in run_goal_rule
self._raise_on_error([t for _, t in throws])
File "/Users/myaccount.g/.cache/pants/setup/bootstrap-Darwin-x86_64/2.0.0rc0_py36/lib/python3.6/site-packages/pants/engine/internals/scheduler.py", line 533, in _raise_on_error
wrapped_exceptions=tuple(t.exc for t in throws),
pants.engine.internals.scheduler.ExecutionError: 1 Exception encountered:
Engine traceback:
in select
in jupyter.goal.jupyter
Traceback (no traceback):
<pants native internals>
Exception: jupyter.goal:27:jupyter() returned a result value that did not satisfy its constraints: <class 'jupyter.goal.Jupyter'>
hundreds-father-404
10/14/2020, 5:57 PMrepl
goal, you’ll return Jupyter(exit_code=0)
. If any part of the rule fails, such as the Pex failing to be created, then the rule will early return with a non-zero exit code. You’ll only reach return Jupyter(exit_code=0)
once the interactive_runner.run()
has finished.hundreds-father-404
10/14/2020, 5:57 PMJupyter()
object?jolly-midnight-72759
10/14/2020, 5:58 PMresult = interactive_runner.run(
InteractiveProcess(
argv=[pex.name], env=None, input_digest=pex.digest, hermetic_env=False
)
)
# exiting from the above with ctrl-c causes the run to end with exit_code 1
# never gets to this part.
exit_code = result.exit_code
<http://logger.info|logger.info>("exit code is {}".format(exit_code)) # XXX make debug
return exit_code
jolly-midnight-72759
10/14/2020, 5:59 PMreturn Jupyter(exit_code=exit_code)
)jolly-midnight-72759
10/14/2020, 5:59 PMhundreds-breakfast-49010
10/14/2020, 6:04 PMjolly-midnight-72759
10/14/2020, 6:04 PMjolly-midnight-72759
10/14/2020, 6:04 PMpantsd
instead of the notebook app.jolly-midnight-72759
10/14/2020, 6:05 PM^C14:02:38.00 [INFO] Sending SIGINT to pantsd with pid 43331, waiting up to 5.0 seconds before sending SIGKILL...
[C 14:02:38.016 NotebookApp] received signal 15, stopping
[I 14:02:38.016 NotebookApp] Shutting down kernels
hundreds-breakfast-49010
10/14/2020, 6:05 PMjolly-midnight-72759
10/14/2020, 6:05 PMjolly-midnight-72759
10/14/2020, 6:05 PMjolly-midnight-72759
10/14/2020, 6:06 PMhundreds-breakfast-49010
10/14/2020, 6:08 PMjolly-midnight-72759
10/14/2020, 6:09 PMjolly-midnight-72759
10/14/2020, 6:10 PMjolly-midnight-72759
10/14/2020, 6:10 PMjolly-midnight-72759
10/14/2020, 6:10 PMjolly-midnight-72759
10/14/2020, 6:11 PMpython_library
targets into my chroot.hundreds-father-404
10/14/2020, 6:20 PMI thought a failed exit might result in the chroot build being marked as invalid.Ah, I didn’t give the full nuance yesterday with my comment. So a
Process
is only cached if the exit code is 0. You’re running a Process
when you say await Get(Pex, PexRequest)
- it’s abstracted away, but underneath, the rule that creates the Pex is literally running a Process
that runs pex -o my_pex.pex req1
.
It doesn’t matter what comes after, like if the rest of the goal rule fails. So long as the Process
to build the Pex succeeds, it’ll be cached.
--
Further, an InteractiveProcess
is never cached. It wouldn’t be safe to cache because there could be user input, which would change what the end result is. So it doesn’t matter with caching if the Jupyter interactive process succeeds or fails.hundreds-father-404
10/14/2020, 6:21 PMNow to get some python_library targets into my chroot.Cool. You’ll want to request
addresses: Addresses
in the @goal_rule
signature, which will get you the addresses of everything specified by the user on the command line
Then use await Get(TransitiveTargets, TransitiveTargetsRequest(addresses))
to pull in the transitive closurehundreds-father-404
10/14/2020, 6:28 PMawait Get(PythonSourceFiles, PythonSourceFilesRequest)
from pants.backend.python.util_rules.python_sources
as a convenience to getting all the relevant source files. You’ll see lots of examples if you grep in the Pants codebase
You may want to set include_files=True
if you want loose files to be usedjolly-midnight-72759
10/14/2020, 6:29 PMPythonSourceFileRequest
and my jupyter_pex?hundreds-father-404
10/14/2020, 6:30 PMPexFromTargetsRequest.for_requirements()
. Check out python/goals/repl.py
and look at the ipython repl to see how we resolve the tool Pex and requirements Pex, then join with --pex-path
. Note that the interpreter constraints should match each otherhundreds-father-404
10/14/2020, 6:30 PMDo I need a step where I combine the PythonSourceFileRequest and my jupyter_pex?Yes, you use
await Get(Digest, MergeDigests)
for this. repl.py
shows thathundreds-father-404
10/14/2020, 6:30 PMrepl.py
, specifically the ipython rulejolly-midnight-72759
10/14/2020, 6:33 PMhappy-kitchen-89482
10/14/2020, 8:01 PMjolly-midnight-72759
10/14/2020, 9:56 PMjolly-midnight-72759
10/14/2020, 9:58 PMctl-\
https://ipython.readthedocs.io/en/stable/whatsnew/version5.html?highlight=Ctrl-%5C#ipython-5-1jolly-midnight-72759
10/15/2020, 1:55 PMCTRL-D
does not exit. CTRL-\
does exit, but pantsd
still gets a SIGQUIT.hundreds-breakfast-49010
10/15/2020, 5:46 PM