Run two python files at the same time

前端 未结 4 1793
遥遥无期
遥遥无期 2021-01-13 23:25

I have tried using

#!/bin/bash
python ScriptA.py &
python ScriptB.py &

to run both scripts at the same time but it always returns

4条回答
  •  梦毁少年i
    2021-01-14 00:10

    I think you are looking for multi-threading

    you could merge your both script into another script, then lauch them using theads

    --edit--

    from threading import Thread
    
    import cv2
    import numpy as np
    import os
    from playsound import playsound
    
    def play_sound(): 
        # import your script A
        a = (r"C:\Users\A\Desktop\sound.mp3")
        playsound(a)
    
    def CV2_stuff():
        # import your script B
        os.environ['SDL_VIDEO_CENTERED'] = '1'
        cap = cv2.VideoCapture("video.mp4")
        ...
    
    
    Thread(target = play_sound).start() 
    Thread(target = CV2_stuff).start()
    

    hope it helps

    this could work too

    import ScriptA
    import ScriptB
    
    ScriptA.function()
    ScriptB.function()
    

    but they wouldn't be exectuted in the same time

提交回复
热议问题