Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Breaking subprocess loop from parent process
What is missing here to read the sent value into my_input and break the loop in Now it runs forever.

Using Debian 10 Buster with Python 3.7.


import sys
import time
import subprocess

command = [sys.executable, '']
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while proc.poll() is None:
    if i > 5:
        #Send BreakLoop after 5th iteration
    print('tok1: '  + str(i))


import sys
import time

my_input =''

while True:
    my_input =
    if my_input == b'exit':
        print('tok2: exiting')
    print('tok2: ' + str(ii))
Use signals instead of sending a text to stdin.
The problem is that tries to read the whole contents of the input stream. This call will block until you close the stdin. You need to send lines instead, so use proc.stdin.write("exit\n".encode()), then sys.stdin.readline() to read a single line of input.
@Gribouillis: Thats it, now it works. Thanks!

@fishhook: Python will run inside an os process started within a Lazarus free pascal application. To communicate with the python, I think pipes must be used. Signals are probably not possible.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Getter/Setter : get parent attribute, but no Getter/Setter in parent nboweb 2 181 May-11-2020, 07:22 PM
Last Post: nboweb
  breaking outof nexted loops Skaperen 4 533 Feb-07-2020, 02:04 AM
Last Post: Skaperen
  Defining parent Class in Python 2.7.11 sarah 2 340 Dec-03-2019, 02:54 AM
Last Post: sarah
  Running function from parent module which has a loop in it. ta2909i 1 272 Nov-18-2019, 07:04 PM
Last Post: Gribouillis
  Breaking While Loop JustWonderful 4 549 Oct-28-2019, 01:12 AM
Last Post: JustWonderful
  (Python help) Change in logic not breaking 'while' loop? btcg2807 1 236 Sep-18-2019, 09:43 AM
Last Post: Larz60+
  How to sharing object between multiple process from main process using Pipe Subrata 1 763 Sep-03-2019, 09:49 PM
Last Post: woooee
  breaking even if conditions is not met Naito 5 862 Feb-03-2019, 12:30 PM
Last Post: perfringo
  parent/add and child/div PyMan 1 661 Feb-23-2018, 04:38 PM
Last Post: nilamo
  Breaking down long function LucasLambert 2 1,407 Mar-30-2017, 06:09 AM
Last Post: LucasLambert

Forum Jump:

Users browsing this thread: 1 Guest(s)