简体   繁体   中英

How to stop/pause an python script embedded in c++

I have a python script that constantly runs in the background and writes it's output to a file, I have initialized it using Python.h class in c++. I want to read from the file when the user make an action, therefore i need to somehow pause or stop the python script.

I would like to know if there is a way of sending c++ pointers to the python function and stopping the script by changing the object in the c++ code. Or maybe force the script to stop. Thanks, Ori.

  • You can force the script to stop using this line of code system("pkill -f name-of-the-python-script"); in the c++ program.
  • You can also use the c++ program to write in another file and check it in every iteration in the python script. If it's empty continue, otherwise: sys.exit() but don't forget to import sys

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM