run several .py file with local packages

42 Views Asked by At

I have several projects in Python cloned from GitHub.

Every project needs to first run a setup.py file to install local packages next I run main.py file to execute the code.

How can I run all projects in one code (.py file)?

I would like to run the first project every minute and the second every 15 seconds.

1

There are 1 best solutions below

2
Ronan Boiteau On

I don't think you need a single .py file, a cron job is what you want.

To setup a cron task, run this command:

crontab -e

It will open a text editor for you to create a new job. Write the following lines inside the text editor, for each line put your absolute path to the main.py file where indicated, then save. It should run your first project every minute and the second project every 15 seconds.

* * * * * python [path to *first* main.py]
* * * * * python [path to *second* main.py]
* * * * * sleep 15 && python [path to *second* main.py]
* * * * * sleep 30 && python [path to *second* main.py]
* * * * * sleep 45 && python [path to *second* main.py]

You can check that your job was saved correctly with the command crontab -l that lists your cron tasks.

I invite you to read some documentation on cron so that you can understand the format used by crontab. Here is a good link