0

I have a simple script that is responsible of fetching data from an external API, lets call it connector.py. That script takes some params as an input ,do its job and then write it to a file and return the output.

I want to implement a scheduler that would create and manage two instances of that script, each with his own input(different settings) and make them run in configured intervals with the next constraint:

  • Input: Pass the parameters of the connector from the settings, to the sub-process via the stdin channel (not as process args)
  • Output: Pass the connector output from the sub-process to the service via the stdout channel
  • I have to implement the constant loop cycle by myself (not use a Scheduler for example)

What mechanisem should I use in order to acheive that goal processes?, threads?, sub-process? Im mainly struggling to understand how to deal with stdin/stdout issue for the different connector instances. Any advice would be appericiated.

Abu Laben
  • 1
  • 1

1 Answers1

0

You have two possibilities whith the scheduling of tasks.

Make your script a factory which will run everytime until something stop it. So you will have the possibility to choose either threads or processes (subprocess use porcess). Here a little description of threads and processes. (If I use this method I would use sub-processes)

What is the difference between a process and a thread?

https://www.backblaze.com/blog/whats-the-diff-programs-processes-and-threads/

However I don't see the utility of using threads or subprocesses in your case because you're telling us that you will make them run in configured intervals. You can just integerate the program to your to make them run separatly.

For task scheduling you also have the use of cronjobs. It allows the execution of commands depending of the date, repetition, user, etc. Here some detail on how setting up a cronjob:

https://phoenixnap.com/kb/set-up-cron-job-linux

Da2ny
  • 897
  • 2
  • 9
  • 24