[Tarantool-patches] [PATCH 1/5] popen: Introduce a backend engine

Cyrill Gorcunov gorcunov at gmail.com
Sat Nov 30 15:16:03 MSK 2019


On Sat, Nov 30, 2019 at 01:54:54PM +0300, Cyrill Gorcunov wrote:
> 
> Forgot to mention that the example in previous message is
> for pipe opened in blocked mode. If o_nonblock used the
> script fails in "read" action. I think the main target now
> for me is to investigate which mode uses python in subprocess
> module and etc (simply because users are familiar with it and
> will expect us to behave the same I think).

Python opens pipes in blocked mode
--- sub.py
import subprocess

args=["sh", "-c", "prompt=''; read -n 5 prompt; echo $prompt"]
process = subprocess.Popen(args, stdout=subprocess.PIPE)
(stdout_data, stderr_data) = process.communicate()
print(stdout_data)
---

$ python3 sub.py
12345b'12345\n'

So it waited for me to type "12345" on keyboard and echo'ed it back.

If we look into strace output we will see

 | pipe2([3, 4], O_CLOEXEC)          = 0

so I think we should follow the convention and open
pipes in blocking mode. Still we could provide an
option to open in nonblocking mode if user wants.

	Cyrill


More information about the Tarantool-patches mailing list