Python Forum
Python code won't execute from the first line to the bottom
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code won't execute from the first line to the bottom
#1
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.
Reply
#2
You never run:
check_kill_process(pstring)
You need to add a line before you sleep statement
Reply
#3
(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
Reply
#4
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the meaning of the line of code. jahuja73 0 314 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  matplotlib x-axis text move bottom upward jacklee26 3 999 May-31-2023, 04:28 AM
Last Post: jacklee26
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,695 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  python-docx regex : Browse the found words in turn from top to bottom Tmagpy 0 1,540 Jun-27-2022, 08:45 AM
Last Post: Tmagpy
  Can a program execute code in iPython shell and get result? deanhystad 3 1,760 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  How To Set Up And Execute A Python File knight2000 4 1,927 May-31-2022, 10:02 AM
Last Post: Larz60+
  Python code to read second line from CSV files and create a master CSV file sh1704 1 2,415 Feb-13-2022, 07:13 PM
Last Post: menator01
  multi-line CMD in one-line python kucingkembar 5 4,001 Jan-01-2022, 12:45 PM
Last Post: kucingkembar
  execute python script guy7200 1 1,606 Oct-25-2021, 09:55 PM
Last Post: Axel_Erfurt
  how long can a line of code be? Skaperen 2 2,224 Jun-09-2021, 06:31 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020