Skip to content

Commit

Permalink
hand-roll wrapper for Popen.__init__
Browse files Browse the repository at this point in the history
... instead of using `fuctools.partialmethod()`

Modules like asyncio that wrap Popen will pass `stdin=None`, bypassing the partial'ed default.

Closes #1484
  • Loading branch information
t-kalinowski committed Sep 20, 2023
1 parent 9cc31aa commit 848608e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions inst/python/rpytools/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@


def patch_subprocess_Popen():
from subprocess import Popen, DEVNULL
from functools import partialmethod
from functools import wraps
import subprocess

Popen.__init__ = partialmethod(Popen.__init__, stdin=DEVNULL)
og_Popen__init__ = subprocess.Popen.__init__

@wraps(subprocess.Popen.__init__)
def __init__(self, *args, **kwargs):
if kwargs.get("stdin") is None:
kwargs["stdin"] = subprocess.DEVNULL
return og_Popen__init__(self, *args, **kwargs)

subprocess.Popen.__init__ = __init__

0 comments on commit 848608e

Please sign in to comment.