question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`poetry run` exits on KeyboardInterrupt

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Arch Linux
  • Poetry version: 0.11.4

Issue

KeyboardInterrupt is not properly handled when executing with poetry run. If a python script attempts to catch a KeyboardInterrupt exception, instead of it being handled, the entire poetry run ... command exists completely.

Here is an example of running the python interpreter.

$ python
>>> try:
...     while True:
...         pass
... except KeyboardInterrupt:
...     print('hello')
...
^Chello
>>> print('I am still in the interpreter')
poetry run python
>>> try:
...     while True:
...         pass
... except KeyboardInterrupt:
...     print('hello')
...
^Chello
$ echo 'I am back to the shell'

Even worse is the way this affects poetry scripts. Completely exiting the script instead of handling the KeyboardInterrupt exception. pyproject.toml

[tool.poetry.scripts]
script = 'script:main'

script.py

def main():
    try:
        while True:
            pass
    except KeyboardInterrupt:
        print('Never reached when executed using `poetry run script`')
$ poetry run script
^C

This does not happen when the package is installed with pip and the script is executed.

$ poetry build
$ pip install dist/project.whl
$ script
^CNever reached when executed using `poetry run script`

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
altendkycommented, Nov 21, 2019

In my experience closing tickets due to being untouched usually just means a valid ticket wasn’t addressed for a long time. I’m glad to hear that this case is an exception and that stale [bot] might go away.

1reaction
stale[bot]commented, Nov 20, 2019

Closing this issue automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

`poetry run` exits on KeyboardInterrupt · Issue #393 - GitHub
I am on the latest Poetry version. I have searched the issues of this repo and believe that this is not a duplicate....
Read more >
Why doesn't this Python keyboard interrupt work? (in PyCharm)
In PyCharm go to "Run"/"Edit Configurations" and check "Emulate terminal ... x == 2: doStuff() else: exit() except KeyboardInterrupt: exit().
Read more >
signal — Set handlers for asynchronous events ... - Python Docs
A long-running calculation implemented purely in C (such as regular expression matching on a large body of text) may run uninterrupted for an...
Read more >
Usage and Invocations — pytest documentation
Running pytest can result in six different exit codes: Exit code 0 ... It also ensures that a stack trace is printed on...
Read more >
python-trio/AnyIO - Gitter
Not so far - just the one thing about CM exits not running. ... If anyio installs its own SIGINT signal handler, KeyboardInterrupt...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found