Python Forum
Subprocess Popen command issues.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subprocess Popen command issues.
#1
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
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)
Reply
#2
The command ulimit is a shell builtin: https://stackoverflow.com/questions/1748...udo-ulimit
Look into the documentation of the module resource: https://docs.python.org/3.6/library/resource.html
I am not sure, if the process invokes the resource limit, which you set inside the Python interpreter. Just try it.

Also you should locate the command nice with which nice. On my Ubuntu system the path is:
Output:
/usr/bin/nice
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Information subprocess.Popen() suddenly giving me grief? davecotter 3 607 Dec-13-2023, 10:49 PM
Last Post: davecotter
  Using subprocess to execute complex command with many arguments medatib531 5 1,847 Apr-27-2023, 02:23 PM
Last Post: medatib531
  Use subprocess.Popen and time.sleep chucky831 2 1,944 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  use subprocess on linux\pi wwith a "grep " command korenron 2 8,072 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,003 May-07-2021, 03:26 PM
Last Post: herwin
  Did subprocess.Popen() causes main routine to pause stdout? liudr 4 3,619 May-04-2021, 08:58 PM
Last Post: liudr
  disable subprocess.popen prompt echo paul18fr 1 2,004 Feb-04-2021, 02:50 AM
Last Post: Larz60+
  how to pass the interactive string to Popen subprocess maiya 1 1,879 Sep-18-2020, 09:36 PM
Last Post: Larz60+
  Error when running mktorrent subprocess command pythonnewbie138 4 3,838 Sep-16-2020, 01:55 AM
Last Post: pythonnewbie138
  How to get program output from subprocess.Popen? glestwid 1 2,366 Aug-19-2020, 05:44 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020