mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
🐚 Python-powered shell. Full-featured and cross-platform.
artificial-intelligencebashclicommand-lineconsoledata-engineeringdata-sciencedevopsfishiterm2pythonraspberry-pisecurity-automationshellxonshzsh
![]() Reading stop signals from the process and update the process state.
### The issue
Technically. In a couple of places that critical for processing signals
we have `os.waitpid()`. The function behavior is pretty unobvious and
one of things is processing return code after catching the signal. We
had no good signal processing around this and this PR fixes this. See
also `proc_untraced_waitpid` function description.
From user perspective. For example we have process that is waiting for
user input from terminal e.g. `python -c "input()"` or `fzf`. If this
process will be in captured pipeline e.g. `!(echo 1 | fzf | head)` it
will be suspended by OS and the pipeline will be in the endless loop
with future crashing and corrupting std at the end. This PR fixes this.
### The solution
Technically. The key function is `proc_untraced_waitpid` - it catches
the stop signals and updates the process state.
From user perspective. First of all we expect that users will use
captured object `!()` only for capturable processes. Because of it our
goal here is to just make the behavior in this case stable.
In this PR we detect that process in the pipeline is suspended and we
need to finish the command pipeline carefully:
* Show the message about suspended process.
* Keep suspended process in `jobs`. The same behavior we can see in
bash. This is good because we don't know what process suspended and why.
May be experienced user will want to continue it manually.
* Finish the CommandPipeline with returncode=None and suspended=True.
### Before
```xsh
!(fzf) # or !(python -c "input()")
# Hanging / Exceptions / OSError / No way to end the command.
# After exception:
$(echo 1)
# OSError / IO error
```
### After
```xsh
!(fzf) # or `!(ls | fzf | head)` or `!(python -c "input()")`
# Process ['fzf'] with pid 60000 suspended with signal 22 SIGTTOU and stay in `jobs`.
# This happends when process start waiting for input but there is no terminal attached in captured mode.
# CommandPipeline(returncode=None, suspended=True, ...)
$(echo 1)
# Success.
```
Closes #4752 #4577
### Notes
* There is pretty edge case situation when the process was terminated so
fast that we can't catch pid alive and check signal
([src](
|
||
---|---|---|
.devcontainer | ||
.github | ||
appimage | ||
ci | ||
docs | ||
news | ||
scripts | ||
tests | ||
xompletions | ||
xonsh | ||
xontrib | ||
.authors.yml | ||
.coveragerc | ||
.gitattributes | ||
.gitignore | ||
.mailmap | ||
.pre-commit-config.yaml | ||
AUTHORS.rst | ||
CHANGELOG.rst | ||
conftest.py | ||
CONTRIBUTING.rst | ||
FUNDING.yml | ||
github_deploy_key.enc | ||
license | ||
logo.txt | ||
MANIFEST.in | ||
pyproject.toml | ||
README.rst | ||
rever.xsh | ||
run-tests.xsh | ||
setup.cfg | ||
setup.py | ||
xonsh-in-docker.py |
xonsh ===== .. class:: center **xonsh** is a Python-powered, cross-platform, Unix-gazing shell language and command prompt. The language is a superset of Python 3.6+ with additional shell primitives. xonsh (pronounced *conch*) is meant for the daily use of experts and novices alike. .. image:: https://raw.githubusercontent.com/xonsh/xonsh/main/docs/_static/what_is_xonsh.png :alt: What is xonsh? :align: center .. class:: center If you like xonsh, :star: the repo, `write a tweet`_ and stay tuned by watching releases. .. image:: https://img.shields.io/badge/Zulip%20Community-xonsh-green :target: https://xonsh.zulipchat.com/join/hbvue5rimpdkwkdjuiqfs7tv/ :alt: Join to xonsh.zulipchat.com .. image:: https://github.com/xonsh/xonsh/actions/workflows/test.yml/badge.svg :target: https://github.com/xonsh/xonsh/actions/workflows/test.yml :alt: GitHub Actions .. image:: https://codecov.io/gh/xonsh/xonsh/branch/master/graphs/badge.svg?branch=main :target: https://codecov.io/github/xonsh/xonsh?branch=main :alt: codecov.io .. image:: https://repology.org/badge/tiny-repos/xonsh.svg :target: https://repology.org/project/xonsh/versions :alt: repology.org First steps *********** Install xonsh from pip: .. code-block:: xonshcon python -m pip install 'xonsh[full]' And visit https://xon.sh for more information: - `Installation <https://xon.sh/contents.html#installation>`_ - using packages, docker or AppImage. - `Tutorial <https://xon.sh/tutorial.html>`_ - step by step introduction in xonsh. Extensions ********** Xonsh has an extension/plugin system. We call these additions ``xontribs``. - `Xontribs on Github <https://github.com/topics/xontrib>`_ - `Awesome xontribs <https://github.com/xonsh/awesome-xontribs>`_ - `Core xontribs <https://xon.sh/api/_autosummary/xontribs/xontrib.html>`_ - `Create a xontrib step by step from template <https://github.com/xonsh/xontrib-template>`_ Projects that use xonsh or compatible ************************************* - `gitsome <https://github.com/donnemartin/gitsome>`_: Supercharged Git/shell autocompleter with GitHub integration. - `xxh <https://github.com/xxh/xxh>`_: Using xonsh wherever you go through the SSH. - `rever <https://regro.github.io/rever-docs/>`_: Cross-platform software release tool. - `Regro autotick bot <https://github.com/regro/cf-scripts>`_: Regro Conda-Forge autoticker. - `zoxide <https://github.com/ajeetdsouza/zoxide>`_: A smarter cd command. - `any-nix-shell <https://github.com/haslersn/any-nix-shell>`_: xonsh support for the ``nix run`` and ``nix-shell`` environments of the Nix package manager. Jupyter-based interactive notebooks via `xontrib-jupyter <https://github.com/xonsh/xontrib-jupyter>`_: - `Jupyter and JupyterLab <https://jupyter.org/>`_: Interactive notebook platform. - `euporie <https://github.com/joouha/euporie>`_: Terminal based interactive computing environment. - `Jupytext <https://jupytext.readthedocs.io/>`_: Clear and meaningful diffs when doing Jupyter notebooks version control. The xonsh shell community ************************* The xonsh shell is developed by a community of volunteers. There are a few ways to help out: - Solve a `popular issue <https://github.com/xonsh/xonsh/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc>`_. You can start with the `Developer guide <https://xon.sh/devguide.html>`_. - Solve a `good first issue <https://github.com/xonsh/xonsh/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22+sort%3Areactions-%2B1-desc>`_. - Take an `idea <https://github.com/xonsh/xontrib-template/issues?q=is%3Aopen+is%3Aissue+label%3Aidea+sort%3Areactions-%2B1-desc>`_ and `create a new xontrib <https://github.com/xonsh/xontrib-template#why-use-this-template>`_. - Become xonsh core by deep diving into xonsh and improve the threading and subprocess logic. - `Become a sponsor to xonsh <https://github.com/sponsors/xonsh>`_. - `Write a tweet`_, post or an article to spread the good word about xonsh in the world. - Give a star to xonsh repository and to `xontribs <https://github.com/topics/xontrib>`_ you like. We welcome new contributors! .. _write a tweet: https://twitter.com/intent/tweet?text=xonsh%20is%20a%20Python-powered,%20cross-platform,%20Unix-gazing%20shell%20language%20and%20command%20prompt.&url=https://github.com/xonsh/xonsh Credits ******* - Thanks to `Zulip <https://zulip.com/>`_ for supporting the xonsh community!