A
A
agent_22032021-08-08 21:15:36
Python
agent_2203, 2021-08-08 21:15:36

How to terminate multiprocessing.Process while the same process is running?

There is a code where during the execution of the process a thread is started, how to terminate the process in the process itself? exit does not help, the thread continues its work

from threading import Thread
from multiprocessing import Process
from time import sleep
from sys import exit

def prcss():
        Thread(target=thrd).start()
        sleep(10)
        print("Exit")
        exit(0)

def thrd():
        while True:
                print("Running")
                sleep(1.5)

prcs = Process(target=prcss)
prcs.start()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-08-08
@agent_2203

Thread(target=thrd, daemon=True).start()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question