Run multiple Python Script at the same time

Kritthanit Malathong
1 min readSep 16, 2022

PLEASE NOTE: If you want to run python file one after other, you can do like this

This method will show you how to run multiple file at the same time let go!

Example

I have 3 python file as below

  1. file_a.py
# file_a.py
import time

n = 0
while True:
print('file a: {0}'.format(n))
n += 1
time.sleep(2)

2. file_b.py

import time

n = 0
while True:
print('file b: {0}'.format(n))
n += 1
time.sleep(2)

3. file_c.py

import time

n = 0
while True:
print('file c: {0}'.format(n))
n += 1
time.sleep(2)

You will see that files A, B and C run forever so you cannot run one after other

Now I want to run ‘file_a.py’, ‘file_b.py’ and ‘file_c.py’ from ‘run_all.py’ so i will do like this

run_all.py

import os
import time
import pyautogui


def press_hotkey():
pyautogui.keyDown('altleft')
pyautogui.keyDown('shift')
pyautogui.keyDown('f10')
pyautogui.keyUp('altleft')
pyautogui.keyUp('shift')
pyautogui.keyUp('f10')
time.sleep(1)
pyautogui.press('num2')


os.system('pycharm F:\\pycharm\\learning\\file_a.py')
time.sleep(1)
press_hotkey()

os.system('pycharm F:\\pycharm\\learning\\file_b.py')
time.sleep(1)
press_hotkey()

os.system('pycharm F:\\pycharm\\learning\\file_c.py')
time.sleep(1)
press_hotkey()

See result

--

--