subprocess

Measuring maximum memory while capturing stdout in Python using subprocess

Measuring maximum memory while capturing stdout in Python using subprocess Question: Is there a clean way to measure the maximum memory consumption of a subprocess while still capturing stdout (and ideally setting a timeout) using subprocess in Python? Capturing output and setting a timeout can easily done using functions of subprocess: output = subprocess.run(cmd, capture_output=True, …

Total answers: 1

What Actually Triggers the Asyncio Tasks?

What Actually Triggers the Asyncio Tasks? Question: Trying to understand python asyncio coming from some background on multithreading with concurrent.futures. Here is the sample script #!/usr/bin/env python3 # encoding: utf-8 """Sample script to test asyncio functionality.""" import asyncio import logging from time import sleep # noqa logging.basicConfig(format=’%(asctime)s | %(levelname)s: %(message)s’, level=logging.INFO) async def wait(i: int) …

Total answers: 1

String interpolation failing inside os.system call

String interpolation failing inside os.system call Question: Editing to skip to the answer: The problem was that the string I was interpolating had a non-ascii character in it that was invisible to the naked eye. I’m trying to run this ImageMagick Command: convert -verbose -size 732×142 xc:transparent -fill black -stroke black -strokewidth 2 -draw "roundrectangle …

Total answers: 2

How to gracefully terminate ffmpeg process alongside with ffprobe process?

How to gracefully terminate ffmpeg process alongside with ffprobe process? Question: I was able to terminate ffmpeg process gracefully when it’s the only ongoing process. Now I also have ffprobe process alongside with ffmpeg process that tracks the progress of the ffmpeg process. It throws the following exception when I try to cancel the process. …

Total answers: 1

Asyncio subprocess is not being cancelled properly on interrupt

Asyncio subprocess is not being cancelled properly on interrupt Question: I have the following code that doesn’t work the way I expected it to. I wanted to be able to interrupt my program with SIGINT (Ctrl-C). It should then cancel tasks that run subprocesses and run some code upon cancellation, but I can’t get that …

Total answers: 1

Faulty returncode of subprocess.run()

Faulty returncode of subprocess.run() Question: import subprocess import time def ping(host): ping_cmd = [‘ping’, host] return subprocess.run(ping_cmd) == 0 online = True while online: response = ping(‘google.com’) print(response) time.sleep(5.0) response should be True, but its False instead. it was working a week ago, am I missing something? tried: response = not ping(‘google.com’) but if the …

Total answers: 1

Read command prompt output in new window in python

Read command prompt output in new window in python Question: I referred to this Read Command Prompt output here. But I can’t get it to work. What I am trying to do is, I open a new command prompt window using subprocess.Popen and I want to run an exe file with some arguments. After I …

Total answers: 1

Extract stdout from long-running process

Extract stdout from long-running process Question: Disclaimer: I have seen many similar questions, but either they do not use asyncio, or they don’t seem to do exactly what I do. I am trying to get the output of a long-running command (it’s actually a server that logs out to stdout) with the following: proc = …

Total answers: 1

How to ensure file has been written to disk before reading it

How to ensure file has been written to disk before reading it Question: I want to read a plan.txt file generated by the fast-downward planner, to do so I’m using subprocess as follows: import subprocess search_options = "lama-first" ## Call Planner cmd = [ "python3", self.planner_path, "–alias", search_options, "–plan-file", self.plan_path, self.domain_path, self.problem_path, ] ## Read …

Total answers: 1