Skip to content

Commit

Permalink
no extra code
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Feb 12, 2024
1 parent 014508a commit f708e44
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions suby/proxy_module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from time import sleep
from threading import Thread, Lock
from threading import Thread
from subprocess import Popen, PIPE
from typing import List, Callable, Union, Optional, Any
from functools import partial
Expand All @@ -13,8 +13,6 @@


class ProxyModule(sys.modules[__name__].__class__): # type: ignore[misc]
lock = Lock()

def __call__(self, *arguments: str, catch_output: bool = False, logger: LoggerProtocol = EmptyLogger(), stdout_callback: Callable[[str], Any] = partial(print, end=''), stderr_callback: Callable[[str], Any] = sys.stderr.write, timeout: Optional[Union[int, float]] = None, token: Optional[AbstractToken] = None) -> SubprocessResult:
"""
About reading from strout and stderr: https://stackoverflow.com/a/28319191/14522393
Expand Down Expand Up @@ -71,6 +69,11 @@ def run_killing_thread(self, process: Popen, token: AbstractToken, result: Subpr
thread.start()
return thread

def run_stderr_thread(self, process: Popen, stderr_buffer: List[str], result: SubprocessResult, catch_output: bool, stderr_callback: Callable[[str], Any]) -> Thread:
thread = Thread(target=self.read_stderr, args=(process, stderr_buffer, result, catch_output, stderr_callback))
thread.start()
return thread

@staticmethod
def killing_loop(process: Popen, token: AbstractToken, result: SubprocessResult) -> None:
while True:
Expand All @@ -82,11 +85,6 @@ def killing_loop(process: Popen, token: AbstractToken, result: SubprocessResult)
break
sleep(0.0001)

def run_stderr_thread(self, process: Popen, stderr_buffer: List[str], result: SubprocessResult, catch_output: bool, stderr_callback: Callable[[str], Any]) -> Thread:
thread = Thread(target=self.read_stderr, args=(process, stderr_buffer, result, catch_output, stderr_callback))
thread.start()
return thread

@staticmethod
def read_stderr(process: Popen, stderr_buffer: List[str], result: SubprocessResult, catch_output: bool, stderr_callback: Callable[[str], Any]) -> None:
for line in process.stderr:
Expand Down

0 comments on commit f708e44

Please sign in to comment.