S
S
sortfact3332021-06-19 07:20:00
Python
sortfact333, 2021-06-19 07:20:00

How to run a function as a subprocess?

I want to complete a piece of code so that the rest of the code continues to work.

def run():
    @eel.expose
    def end_browser():
        print("YES2")
        eel.end()
        eel.close()
        os._exit(0) 

    eel.init('web')
    eel.start("test.html", size=(700,700))
    

run()

import subprocess

process = subprocess.run([???], capture_output=True, shell=True)
print(process.returncode) # вернет 2 в случае ошибки

print("Continue code")


I was advised to use subprocess but I do not understand what needs to be inserted in brackets so that it starts working.
Can anyone explain this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yupiter7575, 2021-06-19
@yupiter7575

eel.start() starts a loop that cannot be stopped through code. Even if you find a way, the program will not reach this section of code.

V
Vindicar, 2021-06-19
@Vindicar

subprocess runs the command as if you typed it in the terminal.
To run a python code function in a parallel process, use multiprocessing .
If you use multiprocessing, wrap the body of your program (i.e., directly executed commands, not function or class declarations) in an idiom . Otherwise, your child processes will try to start their child processes instead of doing what they are told.
if __name__ == '__main__':

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question