Skip to content
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

Jobs #14883

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Jobs #14883

wants to merge 6 commits into from

Conversation

cosineblast
Copy link
Contributor

Description

This is an attempt to improve the nushell situation with regard to issue #247.

This PR aims to implement:

  • spawning jobs: job spawn { do_background_thing }
    Jobs will be implemented as threads and not forks, to maintain a consistent behavior between unix and windows.

  • listing running jobs: job list
    This should allow users to list what background tasks they currently have running.

  • killing jobs: job kill <id>
    This should send an interrupt to an existing job, and ideally, kill any process it is currently executing, if any.

Additionally this PR aims to provide means for nushell jobs to communicate with each other, with channels:

  • channel make, channel send, and channel recv for basic CSP operations.

Things that should be taken into consideration for implementation:

  • Handling TSTP signals while executing code and turning the current program into a background job.
  • Disowning jobs

Roadblocks encountered so far:

  • Nushell does some weird terminal sequence magics which make so that when a background process or thread prints something to stderr and the prompt is idle, the stderr output ends up showing up weirdly

@132ikl
Copy link
Contributor

132ikl commented Jan 21, 2025

looks interesting! by the way, if you haven't seen these PRs which also try to tackle background jobs, and might have some info on roadblocks you might run into. seems like the major blocker was the external printer in reedline.

#11696
nushell/reedline#737

@cosineblast
Copy link
Contributor Author

looks interesting! by the way, if you haven't seen these PRs which also try to tackle background jobs, and might have some info on roadblocks you might run into. seems like the major blocker was the external printer in reedline.

#11696 nushell/reedline#737

Yeah, the mentioned reedline output problems have already shown up. I'll have a look into it, thanks.

This implementation still does not kill the job's current process if it
is executing any, but already sends an interrupt through Signals which
allows the job to be interrupted if it is running nushell code.
We still need to implement unfreezing it after suspending the program,
and killing frozen jobs.

TSTP a unix-specific thing, that could possibly be *emulated* in windows
in the future, but for now, I think implementing this expected unix
shell behaviour is a good call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants