amitt001 / delegator.py

Subprocesses for Humans 2.0.
MIT License
1.7k stars 92 forks source link

Problems using both binary STDIN and STDOUT #51

Closed amotl closed 5 years ago

amotl commented 6 years ago

Dear Kenneth,

Introduction

First things first: While staying for a while with the elder sister of Delegator.py, envoy, we salute you for giving this another attempt to finally regain sanity on Python subprocess handling. We are really looking forward to the outcome, cheers!

After successfully using it for a basic program called formailx.py, we just tried to apply Delegator.py to a slightly more advanced scenario.

Problem

We want to pipe binary data to the STDIN channel of a process and read its binary output from the STDOUT channel.

It is about image conversion using ImageMagick, so let's assume the command we want to execute is

convert - png:-

and we are trying to run Delegator.py like

with open(tiff_file, 'rb') as tiff:
    proc = delegator.run(command)
    proc.send(tiff.read())
    png = proc.out

Following the documentation, we also tried various combinations of the block and binary parameters and attempted to call proc.block() after proc.send(), but everything without success yet.

Status quo

We either get RuntimeError: send can only be used on non-blocking commands. as an answer or the program stalls completely when accessing proc.out.

On the other hand, everything works fine when using the pure subprocess module, see run_command in "util.py" from https://github.com/Patent2net/P2N/pull/26.

Help?

Can we humbly ask you to take a look into this? Thanks in advance for your efforts!

With kind regards, Andreas.

ParthS007 commented 5 years ago

Closing due to inactivity :+1: