mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
🐚 Python-powered shell. Full-featured and cross-platform.
artificial-intelligencebashclicommand-lineconsoledata-engineeringdata-sciencedevopsfishiterm2pythonraspberry-pisecurity-automationshellxonshzsh
![]() ### Motivation There is annoying behavior when you run command in the loop and can't interrupt e.g. [this report](https://github.com/xonsh/xonsh/discussions/5371) and a bit #5342. After diving into this I see the issue around return code. ### The essence Basically ``p = subprocess.Popen()`` populates ``p.returncode`` after ``p.wait()``, ``p.poll()`` or ``p.communicate()`` ([doc](https://docs.python.org/3/library/os.html#os.waitpid)). But if you're using `os.waitpid()` BEFORE these functions you're capturing return code from a signal subsystem and ``p.returncode`` will be ``0`` like success but it's not success. So after ``os.waitid`` call you need to set return code manually ``p.returncode = -os.WTERMSIG(status)`` like in Popen. Example: ```xsh python # python interactive import os, signal, subprocess as sp p = sp.Popen(['sleep', '100']) p.pid # 123 p.wait() # Ctrl+C or `kill -SIGINT 123` from another terminal p.returncode # -2 # BUT: p = sp.Popen(['sleep', '100']) p.pid # 123 pid, status = os.waitpid(p.pid, os.WUNTRACED) # status=2 # From another terminal: kill -SIGINT 123 p.wait() # 0 p.returncode # 0 ``` ```xsh from xonsh.tools import describe_waitpid_status describe_waitpid_status(2) # WIFEXITED - False - Return True if the process returning status exited via the exit() system call. # WEXITSTATUS - 0 - Return the process return code from status. # WIFSIGNALED - True - Return True if the process returning status was terminated by a signal. # WTERMSIG - 2 - Return the signal that terminated the process that provided the status value. # WIFSTOPPED - False - Return True if the process returning status was stopped. # WSTOPSIG - 0 - Return the signal that stopped the process that provided the status value. ``` See also: [Helpful things for knight](https://github.com/xonsh/xonsh/pull/5361#issuecomment-2078826181). ### Before ```xsh $RAISE_SUBPROC_ERROR = True sleep 100 # Ctrl+C _.rtn # 0 # It's wrong and RAISE_SUBPROC_ERROR ignored. for i in range(5): print(i) sleep 5 # 0 # Ctrl+C # Can't interrupt # 1 # 2 ``` ### After ```xsh sleep 100 # Ctrl+C _.rtn # -2 # Like in default Popen $RAISE_SUBPROC_ERROR = True for i in range(5): print(i) sleep 5 # 0 # Ctrl+C # subprocess.CalledProcessError ``` ### Notes * We need to refactor `xonsh.jobs`. It's pretty uncomfortable work with module. * The logic is blurry between Specs, Pipelines and Jobs. We need to bring more clear functions. * The `captured` variable looks like "just the way of capturing (stdout, object)" but in fact it affects all logic very much. We need to create table where we can see the logic difference for every type of capturing. E.g. in `captured=stdout` mode we use `xonsh.jobs` to monitor the command but in `captured=object` we avoid this and some logic from `xonsh.jobs` applied in `stdout` mode but missed in `object` mode. We need clear map. ## For community ⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment** --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> |
||
---|---|---|
.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. 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!