1

first of all a short overview over my current goal:

I want to use a scheduler to execute a simple python program every second. This program reads some data and enter the results inside a database. Because the scheduled task will operate over several days on a raspberry pie the process should start in the background. Therefore I want to create a python file which can start, stop and get the current status from the background job. Furthermore it should be possible to exit and reenter the control file without stopping the background job.

Currently I tried apscheduler to execute the python file every second. The actual problem is, that I can't access the current python file, to control the status, from another external file. Overall I found no real solution how I can control a subprocess form an external file and after find the same subprocess again after restarting the controlling python file.

EDIT:

So overall as far I got it now I'm able to find the current process with his pid. With that im able to send send a terminatesignal to the current process. Inside my scheduled file I'm able to catch these signals and shut down the program on a normal way.

1 Answer 1

1

To control (start, restart, stop, schedule) the background process use subprocess. Here is example of subrocess' popen with timeout.

To pass some data between the scheduler and the background job use one of IPC mechanisms, for example sockets.

Sign up to request clarification or add additional context in comments.

4 Comments

Okay to control the process I'm able to use subprocess but how can I find the running subprocess again after restarting the controller (mainprocess)?
No, subprocess created using python's subprocess would normally end after the controlling program ends.
@VeitBjarsch you may use linux tools like ps for that, see example.
The problem is that this will kill the process on a hard way and not exit ist normally. I found this. Maybe it will help with my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.