Skip to content

Commit

Permalink
This does not need to be a static method
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcantrell committed Jan 26, 2024
1 parent 67b96fe commit b9335e9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/swaystatus/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
from subprocess import Popen, PIPE


def proxy_lines(pipe, handler):
with pipe:
for line in pipe:
handler(line)


class PopenStreamHandler(Popen):
"""
Just like `Popen`, but handle stdout and stderr output in dedicated
threads.
"""

@staticmethod
def _proxy_lines(pipe, handler):
with pipe:
for line in pipe:
handler(line)

def __init__(self, stdout_handler, stderr_handler, *args, **kwargs):
kwargs["stdout"] = PIPE
kwargs["stderr"] = PIPE
super().__init__(*args, **kwargs)
Thread(target=self._proxy_lines, args=[self.stdout, stdout_handler]).start()
Thread(target=self._proxy_lines, args=[self.stderr, stderr_handler]).start()
Thread(target=proxy_lines, args=[self.stdout, stdout_handler]).start()
Thread(target=proxy_lines, args=[self.stderr, stderr_handler]).start()

0 comments on commit b9335e9

Please sign in to comment.