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.

Zombie/orphan processes with piped shim executables from entry points, when using editable flag under PowerShell Core

See original GitHub issue

Environment

  • pip version: 20.2.4
  • setuptools version: 50.3.2
  • Python version: 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
  • PowerShell Core version: 7.0.3
  • OS: Windows 10 Pro 1909 Build: 18363.1139

Description

Some piped shim executables created with pip install --editable . command, seem to hang/morph into zombie/orphan processes under PowerShell Core, when interrupted with Ctrl-C.

This issue doesn’t exist under CMD/Cygwin or if the install is done without the --editable flag. This is why I report the issue here, but it might be a problem with third-party/upstream package or the PowerShell Core machinery itself. Please advise/close if pip is not the source for this issue.

Expected behavior

I expect piped shim executables to exit cleanly/properly upon interruption and not leaving hanging zombie processes.

How to Reproduce

  1. Setup:

Folder structure:

$ tree
t
├── baz
│   ├── __init__.py
│   ├── foo.py
│   └── bar.py
└── setup.py

Example minimal setup.py file:

from setuptools import setup, find_packages

setup(
    name='t',
    version='1.0.0',
    url='https://example.com',
    author='Author Name',
    author_email='author@example.com',
    description='Description',
    packages=find_packages(),
    entry_points = {
        'console_scripts': ['foo=baz.foo:main', 'bar=baz.bar:main'],
    },
    install_requires = ['aioconsole>=0.3.1'],
)

Example script foo.py:

from asyncio import run
from asyncio import sleep
from aioconsole.stream import aprint


async def _main():
    while True:
        await aprint('a')
        await sleep(5)


def main():
    run(_main())


if __name__ == '__main__':
    exit(main())

Example script bar.py:

from asyncio import run

from aioconsole.stream import aprint
from aioconsole.stream import get_standard_streams


async def _main():
    reader, _ = await get_standard_streams()
    async for line in reader:
        await aprint(line)


def main():
    run(_main())


if __name__ == '__main__':
    exit(main())

Archive with all example files: t.zip

  1. Create virtualenv and install the package with:
virtualenv venv
. .\venv\Scripts\activate
pip install --editable .
  1. Run the two shim executables with pipe and interrupt the command after a couple of seconds with Ctrl+C.
foo | bar
  1. Check for any zombie/hanging processes - example: image

Output Incorrect output under PowerShell Core:

(venv) PS D:\t> foo | bar
b'a\n'
b'a\n'
Traceback (most recent call last):
  File "D:\t\venv\Scripts\foo-script.py", line 33, in <module>
    sys.exit(load_entry_point('t', 'console_scripts', 'foo')())
  File "d:\t\baz\foo.py", line 13, in main
    run(_main())
  File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 596, in run_forever
    self._run_once()
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 1854, in _run_once
    event_list = self._selector.select(timeout)
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 434, in select
    self._poll(timeout)
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 783, in _poll
    status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
KeyboardInterrupt

Correct output under CMD (notice the two tracebacks):

(venv) D:\t>foo | bar
b'a\n'
b'a\n'
Traceback (most recent call last):
  File "D:\t\venv\Scripts\foo-script.py", line 33, in <module>
    sys.exit(load_entry_point('t', 'console_scripts', 'foo')())
  File "d:\t\baz\foo.py", line 13, in main
    run(_main())
  File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 596, in run_forever
    self._run_once()
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 1854, in _run_once
    event_list = self._selector.select(timeout)
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 434, in select
    self._poll(timeout)
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 783, in _poll
    status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
KeyboardInterrupt
^Traceback (most recent call last):
C  File "D:\t\venv\Scripts\bar-script.py", line 33, in <module>
    sys.exit(load_entry_point('t', 'console_scripts', 'bar')())
  File "d:\t\baz\bar.py", line 14, in main
    run(_main())
  File "C:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 596, in run_forever
    self._run_once()
  File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 1854, in _run_once
    event_list = self._selector.select(timeout)
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 434, in select
    self._poll(timeout)
  File "C:\Program Files\Python39\lib\asyncio\windows_events.py", line 783, in _poll
    status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
KeyboardInterrupt
^C

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pfmoorecommented, Nov 6, 2020

Yeah, I’m pretty confident this isn’t a pip issue. Feel free to @-ping me on the setuptools issue if anything I’ve said here needs clarification.

0reactions
int3lcommented, Nov 6, 2020

Closing this one for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Pipeline Chain Operators - PowerShell | Microsoft Learn
Describes chaining pipelines with the `&&` and `||` operators in PowerShell.
Read more >
Running PowerShell Scripts in Azure DevOps Pipelines (2 of 2)
To run a PowerShell script in a pipeline requires using the ... will force the code/script to be executed using pwsh.exe (PowerShell Core)....
Read more >
How to exclude an executable from getting shimming in a ...
Workaround. The solution, as a Chocolatey package user, is to pass a specific option to the command line you use: my_program.exe -- ...
Read more >
PowerShell Executable Location | List of ... - eduCBA
The executable file can execute both PowerShell cmdlets and scripts. This article will cover in detail the exe file of the PowerShell. Syntax:...
Read more >
PowerShell - Wikipedia
PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting ...
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