Answers for "run a python script using subprocess"

23

execute command in python script

import os

os.system("ma Commande")

#Exemple:

os.system("cd Documents")
Posted by: Guest on June-10-2020
0

python run function in subprocess

# no, we can't use subprocess module for that
import multiprocessing
import time


def task(*args):
    print("wait")
    time.sleep(2)
    print(*args)
    print("finished")


if __name__ == "__main__":
    # child process has different __name__
    process = multiprocessing.Process(target=task, args=(69, 66))
    # args must be pickable
    # Pickable objects https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled
    process.start()
    process.join()  # make sure this gets executed only after process starts
Posted by: Guest on October-10-2021

Code answers related to "run a python script using subprocess"

Python Answers by Framework

Browse Popular Code Answers by Language