CBAPKA 0 Posted March 10 (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 March 10 by CBAPKA Share this post Link to post
CBAPKA 0 Posted March 10 import time while True: print('something') timer.sleep(5) #need to stop it Share this post Link to post
AlexanderMi 0 Posted April 24 (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 April 24 by AlexanderMi Share this post Link to post