Answer the question
In order to leave comments, you need to log in
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")
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question