Posts

Showing posts with the label subprocess

How to (can I) ask a PIPE how many bytes it has available for reading?

Image
Clash Royale CLAN TAG #URR8PPP How to (can I) ask a PIPE how many bytes it has available for reading? I've implemented a non-blocking reader in Python, and I need to make it more efficient. The background: I have massive amounts of output that I need to read from one subprocess (started with Popen()) and pass to another thread. Reading the output from that subprocess must not block for more than a few ms (preferably for as little time as is necessary to read available bytes). Currently, I have a utility class which takes a file descriptor (stdout) and a timeout. I select() and readline(1) until one of three things happens: select() readline(1) Then I return the buffered text to the calling method, which does stuff with it. Now, for the real question: because I'm reading so much output, I need to make this more efficient. I'd like to do that by asking the file descriptor how many bytes are pending and then readline([that many bytes]) . It's supposed to just pass stuff ...

subprocess sometimes sends returns empty

Image
Clash Royale CLAN TAG #URR8PPP subprocess sometimes sends returns empty I have the following class that is used to run a third party command line tool which I have no control over. I run this ina Qthread in a PyQt Gui. Qthread PyQt I turn the gui into an EXE using Pyinstaller gui EXE Pyinstaller Problems are more prevalent when it is an EXE EXE class CLI_Interface: def process_f(self, command, bsize=4096): self.kill_process(CLI_TOOL) startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE p = Popen(command, stdout=PIPE, stderr=PIPE, startupinfo=startupinfo, bufsize=bsize, universal_newlines=True) try: out, err = p.communicate(timeout=120) except TimeoutExpired: p.kill() out, err = p.communicate() return out.split(), err.split() def kill_process(self, proc): # Check process is ru...