2017-02-14 5 views
0

Avec l'utilisation de docker-compose et python:2.7, il fonctionne correctement lors de l'exécution seulement while 1 boucle et time.sleep(1) séparément.docker bloque lors de l'exécution time.sleep (1) dans une boucle python

Mais il colle quand vous les exécutez ensemble.

Voici la version docker et le contenu du fichier sur mon mac

tmp docker -v 
Docker version 1.12.5, build 7392c3b 
tmp cat docker-compose.yml 
version: '2' 
services: 
    test: 
     image: python:2.7 
     command: [python, -c, "print 0\nwhile 1:\n\tprint 1\n\tbreak"] 
tmp docker-compose up 
Creating network "tmp_default" with the default driver 
Creating tmp_test_1 
Attaching to tmp_test_1 
test_1 | 0 
test_1 | 1 
tmp_test_1 exited with code 0 
tmp cat docker-compose.yml 
version: '2' 
services: 
    test: 
     image: python:2.7 
     command: [python, -c, "print 0\nimport time\nprint time.sleep(1)"] 
tmp docker-compose up 
Recreating tmp_test_1 
Attaching to tmp_test_1 
test_1 | 0 
test_1 | None 
tmp_test_1 exited with code 0 
tmp cat docker-compose.yml 
version: '2' 
services: 
    test: 
     image: python:2.7 
     command: [python, -c, "print 0\nimport time\nwhile 1:\n\tprint time.sleep(1)"] 
tmp docker-compose up 
Recreating tmp_test_1 
Attaching to tmp_test_1 

et ici il stucks.

Espérons connaître la raison et la méthode pour la réparer, merci.

Répondre

1

Ajouter -u drapeau à python afin d'avoir stdout unbuffered:

command: [python, -uc, "print 0\nimport time\nwhile 1:\n\tprint time.sleep(1)"] 
+0

Il fonctionne. Et dans la page man de python, il y a des détails sur la mise en mémoire tampon interne. Merci. – Roy