Jul-03-2017, 01:39 AM
I am having troubles using subprocess.Popen as it seems to give me an error when I try specifying the process to open test to test.py
If I leave it as test it seems to create a subprocess but the return code isn't correct(should be 42 not 1) and I don't get anything piped to stdout or stderr.
However, if it is test.py I get this output
stderr: b'nice: \xe2\x80\x98test.py\xe2\x80\x99: No such file or directory\n'
Process completed: 127
If I get rid of the ulimit memory and nice flags it works completely fine? Is there any I could keep those flags in place. I would like to limit the amount of memory and allow for the process to throttle itself for other processes?
I have both of my files located in the same directory on the desktop and I'm using python version 3.5.2 on Linux Mint.
sub_proc.py
If I leave it as test it seems to create a subprocess but the return code isn't correct(should be 42 not 1) and I don't get anything piped to stdout or stderr.
However, if it is test.py I get this output
stderr: b'nice: \xe2\x80\x98test.py\xe2\x80\x99: No such file or directory\n'
Process completed: 127
If I get rid of the ulimit memory and nice flags it works completely fine? Is there any I could keep those flags in place. I would like to limit the amount of memory and allow for the process to throttle itself for other processes?
I have both of my files located in the same directory on the desktop and I'm using python version 3.5.2 on Linux Mint.
sub_proc.py
import os import sys import signal import subprocess print("Program starting, version: ", sys.version) process = subprocess.Popen([sys.executable, "test.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE); #This one works as expected #process = subprocess.Popen([sys.executable, 'ulimit -v 16384; nice -n 15 test.py'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #This one does nothing, appears frozen? Removing shell as an argument then gives me an error that it can't find the file? #process = subprocess.Popen('ulimit -v 16384; nice -n 15 test.py', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) #Outputs stderr: b'nice: \xe2\x80\x98test.py\xe2\x80\x99: No such file or directory\n' Process completed: 127 try: out, err = process.communicate(timeout=3) if out: print("stdout: ", out) if err: print("stderr: ", err) print("Process completed: ", process.returncode) except subprocess.TimeoutExpired: print("TIMEOUT") process.kill()test.py
import sys print("Hello from test.py") sys.exit(42)