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

popen2 is missing for Python3 #1

Open
sibskull opened this issue May 26, 2021 · 1 comment
Open

popen2 is missing for Python3 #1

sibskull opened this issue May 26, 2021 · 1 comment

Comments

@sibskull
Copy link

$ python3 processes_test.py
Traceback (most recent call last):
File "/usr/src/RPM/BUILD/eventlib-0.3.0/greentest/processes_test.py", line 25, in
from eventlib import processes
File "/usr/lib/python3/site-packages/eventlib/processes.py", line 22, in
import popen2
ModuleNotFoundError: No module named 'popen2'

Please, rewrite implementation of processes handling from popen2 to subprocess.Popen: https://stackoverflow.com/questions/3892556/subprocess-replacement-of-popen2-with-python

@sibskull
Copy link
Author

sibskull commented May 26, 2021

Quick patch:

index bdc1349..6355617 100644
--- a/eventlib/processes.py
+++ b/eventlib/processes.py
@@ -19,7 +19,7 @@
 
 import errno
 import os
-import popen2
+import subprocess
 import signal
 
 from eventlib import coros
@@ -98,10 +98,10 @@ class Process(object):
         self.popen4 = None
 
         ## We use popen4 so that read() will read from either stdout or stderr
-        self.popen4 = popen2.Popen4([self.command] + self.args)
+        self.popen4 = subprocess.Popen([self.command] + self.args, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
         self.event = _add_child_pobj(self.popen4)
-        child_stdout_stderr = self.popen4.fromchild
-        child_stdin = self.popen4.tochild
+        child_stdout_stderr = self.popen4.stdout
+        child_stdin = self.popen4.stdin
         greenio.set_nonblocking(child_stdout_stderr)
         greenio.set_nonblocking(child_stdin)
         self.child_stdout_stderr = greenio.GreenPipe(child_stdout_stderr)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant