Python Forum

Full Version: Python code won't execute from the first line to the bottom
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having a hard time figuring out what is happening with this code:

print("Starting...")
import os, signal
import json
import zmq
from time import sleep

context = zmq.Context()
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5563")


def check_kill_process(pstring):
    for line in os.popen("ps ax | grep " + pstring + " | grep -v grep"):
        fields = line.split()
        pid = fields[0]
        os.kill(int(pid), signal.SIGKILL)

sleep(6)
If I run this in my docker container, it outputs "Starting..." immediately after I run the code, and then exists after 6 seconds.

However, if I run this inside the same docker container but started by docker-compose, it does the following:

after I start docker-compose, it waits 6 seconds and then prints "Starting..."

It's the same container, but one is called directly from the terminal, and the other is called by docker-compose. Could somebody help me debug this process? The container is running ubuntu 16.04, python 3.5 I guess.
You never run:
check_kill_process(pstring)
You need to add a line before you sleep statement
(Dec-19-2017, 11:39 PM)Larz60+ Wrote: [ -> ]You never run:
check_kill_process(pstring)
You need to add a line before you sleep statement

Sorry, the intention was to not run this anyway.

(Dec-19-2017, 11:39 PM)Larz60+ Wrote: [ -> ]You never run:
check_kill_process(pstring)
You need to add a line before you sleep statement

the problem persists if I take off this function. I don't know why I've put it there
I don't use docker, but apparently
  socket.bind("tcp://*:5563")
returns immediately after execution.
so it would seem that everything is indeed executing, but perhaps not as expected.
What were you expecting?