Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated asyncio.get_child_watcher() #584

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions pynvim/msgpack_rpc/event_loop/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,36 @@ async def connect_stdout():

@override
def _connect_child(self, argv: List[str]) -> None:
if os.name != 'nt':
# see #238, #241
self._child_watcher = asyncio.get_child_watcher()
self._child_watcher.attach_loop(self._loop)
def can_use_pidfd():
# Unix system without pidfd_open?
if not hasattr(os, 'pidfd_open'):
return False

# Check that we are not blocked by security policy like SECCOMP
try:
pid = os.getpid()
fd = os.pidfd_open(pid, 0)
os.close(fd)
except OSError:
return False

return True

def get_child_watcher():
if can_use_pidfd():
try:
from asyncio.unix_events import PidfdChildWatcher
return PidfdChildWatcher()
except ImportError:
pass

try:
from asyncio.unix_events import ThreadedChildWatcher
return ThreadedChildWatcher()
except ImportError:
pass

return asyncio.get_child_watcher()

async def create_subprocess():
transport: asyncio.SubprocessTransport # type: ignore
Expand All @@ -200,6 +226,12 @@ async def create_subprocess():
pid = transport.get_pid()
debug("child subprocess_exec successful, PID = %s", pid)

if os.name != 'nt':
watcher = get_child_watcher()

watcher.attach_loop(self._loop)
self._child_watcher = watcher

self._transport = cast(asyncio.WriteTransport,
transport.get_pipe_transport(0)) # stdin
self._protocol = protocol
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup

install_requires = [
'msgpack>=0.5.0',
'msgpack>=1.0.0',
'greenlet>=3.0; python_implementation != "PyPy"',
'typing-extensions>=4.5; python_version < "3.12"',
]
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[tox]
min_version = 4.0
envlist =
py{37,38,39,310,311,312}-asyncio
py{37,38,39,310,311,312,313}-asyncio
checkqa
skip_missing_interpreters =
true
Expand All @@ -18,6 +18,7 @@ python =
3.10: py310
3.11: py311
3.12: py312
3.13: py313
pypy3: pypy3

[testenv]
Expand Down
Loading