From bd234af0a9e610e2cee8506e68936edeeef1e47d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sun, 30 Oct 2016 03:27:10 -0400 Subject: [PATCH] dockcross: Prevent dockcross from blocking when used with Python subprocess As explained in [1], when using dockcross from python subprocess, the interactive mode is disabled and output of "cat /dev/urandom" is block buffered instead of being line buffered. Workaround to this problem is to simply read a fixed amount of characters from urandom. The following two snippets illustrates the problem and the the implemented solution: Works ```python import subprocess as sp sp.check_call("var=$(head -c 500 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1); echo $var", shell=True) ``` => output random string Fail: ```python import subprocess as sp sp.check_call("var=$(cat /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1); echo $var", shell=True) ``` => Hang [1] http://stackoverflow.com/questions/16805827/unable-to-read-stdout-from-a-running-process#16806506 --- imagefiles/dockcross | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagefiles/dockcross b/imagefiles/dockcross index e4b18a5..6f3f319 100755 --- a/imagefiles/dockcross +++ b/imagefiles/dockcross @@ -180,7 +180,7 @@ fi # Now, finally, run the command in a container # tty -s && TTY_ARGS=-ti || TTY_ARGS= -CONTAINER_NAME=dockcross_$(cat /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1) +CONTAINER_NAME=dockcross_$(head -c 500 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | fold -w 7 | head -n 1) docker run $TTY_ARGS --name $CONTAINER_NAME \ -v $PWD:/work \ $USER_IDS \