Jump to content
Sign in to follow this  
CBAPKA

python4delphi How to stop inifinity script

Recommended Posts

Posted (edited)

Greetings, I have several pieces of Python code that checks one condition in a loop, if it is met, it outputs Print, if not waits 5 seconds and checks again, and so on endlessly. How do I stop the script using delphi? Can I somehow send ctrl+c or something like that there. The answer from Demo33 did not fit

 

v - 3.12.dll

Edited by CBAPKA

Share this post


Link to post
import time

while True:
  print('something')
  timer.sleep(5)
  
#need to stop it

 

Share this post


Link to post
Posted (edited)

from delphi side provide a py module and in run-time create an  instance of class which holds "Terminated" property (and you able to get/set), and set it as variable for module. Then in python you can run infinite loop so long as needed:

from DelphiModule import RuntimeVar
from time import sleep
from pyio import write as print

def run():
  while not RuntimeVar.Terminated:
    print('Wauting for something')
    sleep(1) #1 second sleep
  else:
    print('infinite loop ended by delphi side')

run()

until host app not set Terminated to true yet.

Due to that design, your python code should run in thread. 

 

Edited by AlexanderMi

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×