How to run same process simultaneously - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to run same process simultaneously (/thread-21209.html) |
How to run same process simultaneously - exploit123 - Sep-19-2019 I have a jar and I want to make a python script for linux that checks if the jar is opened in the linux task manager and if its not to open it 5 times. From time to time it should check the 5 processes and when all 5 end open them again. This is the code that I`ve written in python: import psutil import subprocess process_name = "/root/Linux/ArhivareProd.jar" for proc in psutil.process_iter(): process = psutil.Process(proc.pid) pname = process.name() if pname != process_name: subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar']) subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar']) subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar']) subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar']) subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar']) else: print("Minim un proces ArhivareProd.jar deja ruleaza !")When I run it it only opens one jar process How can I modify the script so it opens up 5 processes ? Thanks RE: How to run same process simultaneously - Gribouillis - Sep-19-2019 Try procs = [] for i in range(5): p = subprocess.Popen(['java','-jar','/root/Linux/ArhivareProd.jar']) procs.append(p) from p in procs: p.wait() |