-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Consider execv
for uv run
on Unix
#3095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Edit: The below concern has found other solutions since then, and is not really relevant. For the https://github.com/bluss/pyproject-local-kernel usecase (sorry if this is boring), spawn vs exec would make a difference on Linux in terms of how a jupyter notebook is kernel is launched. jupyter lab launches my python script -> launches uv run -> launches ipykernel. My script already handles forwarding posix signals to the child (first arrow). If you use exec, the second arrow disappears and posix signals are forwarded to the ipykernel which is useful, in fact the ipykernel doesn't want to start correctly if it doesn't have that signal path. I think exec is generally what you'd want to do. I didn't run into this with rye run, because it uses exec on Linux. I could configure my kernel with interrupt_mode=message (instead of default signal) to make this issue disappear, but maybe that shouldn't be needed. (Edit, no interrupt_mode=message is only fully supported on Linux, not on Windows, so this is not a great option). |
Is this still possible, how does the ephemeral venv cleanup work? Is it using a scope based cleanup. I'll file another issue that's related to ipykernel, and maybe we'll find a good solution. |
It is not clear how we'd clean up the ephemeral environment, that's a good question. |
It runs on Drop. |
The pyproject-local-kernel usecase seems to work perfectly on Linux now after the #5257 fix I think 🤩. Probably should carry over to windows too. Thanks for the help with this 🙂 uv run --with ipykernel is perfect for the notebook use case, it's very smooth. |
Awesome. I did test on my Windows machine and it worked as expected for me, so hopefully good there too... |
When you |
Basically, you can think of So to make this work here, we'd probably want to bubble some instruction to "run this Also, we are very likely already using |
Hm.. thanks for the details. I think that supports my concern that we have resources e.g., the ephemeral environment, that can't be removed until the spawned process finishes which makes it hard to entirely cede control? |
Oh I see, yes, hmmm. That is a conundrum. I am reminded of a trick where you can unlink a file but keep an open file descriptor to it, which at least on Unix, will keep the file around until the descriptor is closed. But, 1) I'm not sure how to make that scale to an entire directory tree and 2) I'm not sure if that concept works on Windows. Failing some trick like that, I'd guess the only way to do this is to introduce some kind of garbage collection? Not sure. |
Yeah I think the general form of the problem here is that |
This feels like a pretty significant blocker for switching to |
Yeah, agreed. |
Signal handling was improved #11009 I think the |
More signal handling changes in #13017 |
As I suspected quite some time ago (#6738 (comment)), it's problematic that we don't handle _every_ signal here. This PR adds handling for all of the Unix signals except `SIGCHLD`, `SIGIO`, and `SIGPOLL` which seem incorrect to forward. Also notable, we _cannot_ handle `SIGKILL` so if someone sends that to the PID instead of the PGID, they will leave dangling subprocesses. Instead, we could use `exec` and avoid this handling. However, we'd lose the ability to add nice error message on failure (e.g., as someone is trying to add in #12201) and, more critically, we'd need to figure out how to clean up resources properly (i.e., temporary directories) which currently happens on `Drop`. In the long-term, we'll probably want an option to use `exec` — but we'll need to figure out when to clean up resources or accept that they will dangle. This was last discussed in #3095 — discussion on that approach should continue there. A note on the implementation: I spent time time trying to write the handler using a tokio stream, so we could dynamically iterate over a list of signals instead of copy/pasting the implementation — I couldn't get it to work though and it didn't seem critical. Closes #12830
See #3074 (comment)
The text was updated successfully, but these errors were encountered: