开发者

python running multiple instances

开发者 https://www.devze.com 2023-01-22 07:44 出处:网络
hi lets assume i have a simple programm in python. This programm is running every five minutes throught cron. but i dont know how to write it so the programm will allow to run multiple processes of it

hi lets assume i have a simple programm in python. This programm is running every five minutes throught cron. but i dont know how to write it so the programm will allow to run multiple processes of its self simultaneously. i want to开发者_StackOverflow社区 speed things up ...


I'd handle the forking and process control inside your main python program. Let the cron spawn only a single process and that process be a master for (possible multiple) worker processes.

As for how you can create multiple workers, there's the threading module for multi threading and multiprocessing module for multi processing. You can also keep your actual worker code as separate files and use the subprocess module.

Now that I think about it, maybe you should use supervisord to do the actual process control and simply write the actual work code.

0

精彩评论

暂无评论...
验证码 换一张
取 消