Skip to content

poetry run should use execve syscall #993

Closed

Description

@ejholmes
  • 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: any
  • Poetry version: 11.5
  • Link of a Gist with the contents of your pyproject.toml file:

Issue

When running a program through poetry run, subprocess.call is used to execute the command. This has the negative side effect of causing poetry to swallow all signals, making it difficult to wrap commands that depend on signals to be handled properly.

I think the behavior that poetry run should have is that the command provided is exec'd using the exceve syscall, which will replace the process and allow signals to be handled properly. This is similar to the behavior of similar utilities, like bundle exec in ruby.

Poetry should play nice with other unix utilities.

Steps to reproduce

$ cd $(mktemp -d)
$ poetry init
$ go get -u github.com/ejholmes/sigp
$ sigp sleep 60 &
$ kill -TERM $!
signal 15 received (terminated)
signal 20 received (child exited)
$ poetry run sigp sleep 60 &
$ kill -TERM $! # notice that sigp doesn't print anything, because it didn't get the TERM signal
$ ps -A | grep sigp # zombie process now
18862 ttys013    0:00.01 sigp sleep 60

Activity

  1. drunkwcodes commented on Mar 28, 2019

    @drunkwcodes

    subprocess.run() is good for it. But supported platforms has to be updated to python 3.5+.

  2. floer32 commented on Mar 28, 2019

    @floer32

    I agree with OP that this is a great idea; should probably be a flag though, ie poetry run --exec (short form poetry run -x or something)

  3. simnalamburt commented on Jul 18, 2019

    @simnalamburt

    AFAIK both subprocess.run() and subprocess.call() create subprocess. os.execve would be suffice.

    And I think execve() should be a new default of poetry run. Maintaining an intermediate process between user shell and actual process gives you only burdens to care without good benefit.

  4. digitalresistor commented on Jul 23, 2019

    @digitalresistor
    Contributor

    https://github.com/bertjwregeer/vrun/blob/master/src/vrun/oscompat.py

    Someone please steal that code... unfortunately on Windows you can't use os.execve, so you have to use popen instead.

  5. joekohlsdorf commented on Aug 7, 2019

    @joekohlsdorf

    poetry shell should do the same

  6. benjirewis commented on Mar 30, 2023

    @benjirewis

    I've noticed killing poetry processes with SIGTERM creates a status code of 143. While that error code does indicate graceful termination after receiving SIGTERM, why not just return 0?

  7. github-actions commented on Feb 29, 2024

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  8. locked as resolved and limited conversation to collaborators on Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions