python call external program non-blocking way

后端 未结 2 800
刺人心
刺人心 2020-12-10 19:19

is there a way to call an external program inside python and don\'t wait for its execution to finish?

I tried this, but no luck:

os.system(\"external         


        
2条回答
  •  离开以前
    2020-12-10 20:05

    Yes, use the subprocess module. For example:

    p = subprocess.Popen(['external_program', 'arg1', 'arg2'])
    # Process is now running in the background, do other stuff...
    ...
    # Check if process has completed
    if p.poll() is not None:
        ...
    ...
    # Wait for process to complete
    p.wait()
    

提交回复
热议问题