mirror of
https://github.com/bensuperpc/dockcross.git
synced 2025-01-22 22:25:41 +01:00
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
This commit is contained in:
parent
3288c877e5
commit
bd234af0a9
@ -180,7 +180,7 @@ fi
|
|||||||
# Now, finally, run the command in a container
|
# Now, finally, run the command in a container
|
||||||
#
|
#
|
||||||
tty -s && TTY_ARGS=-ti || TTY_ARGS=
|
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 \
|
docker run $TTY_ARGS --name $CONTAINER_NAME \
|
||||||
-v $PWD:/work \
|
-v $PWD:/work \
|
||||||
$USER_IDS \
|
$USER_IDS \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user