python-poetry / python-poetry/poetry

Plugins cannot respond to `TERMINATE` event on non-Windows systems after `poetry run`

Open
#8,092 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/plugin-api area/windows kind/bug status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

  • Poetry version: 1.5.1
  • Python version: 3.10.7
  • OS version and name: Windows 11
  • pyproject.toml: Any
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

On non-Windows systems, poetry run uses os.execvpe:

https://github.com/python-poetry/poetry/blob/6e942983dff1bcc6d307c7704e8159df0c959a16/src/poetry/utils/env/generic_env.py#L90-L91

Because of how this function replaces the current process, a plugin cannot respond to the TERMINATE event. atexit hooks are also not called.

Could subprocess.Popen simply be used for all systems instead of Windows only?

My use case is that my plugin makes some temporary modifications to set the version number, and it needs to revert them when the command is done. Right now, I just have the plugin ignore poetry run and poetry shell since it can't clean up after them.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/poetry/utils/env/generic_env.py at the referenced os.execvpe call and compare its non-Windows behavior with the Windows subprocess.Popen path. Reproduce poetry run with a plugin that listens for the TERMINATE event, then verify that the event and cleanup hooks run after the command completes on non-Windows systems.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.