How to reference a stream in Pyhton 3?

I am trying to call a thread that I define in a function from another function. Here is the first function whose purpose is to create and start a thread:

def startThread(func):

    listen = threading.Thread(target = func)
    listen.start()

I am trying to implement a function that closes the thread created in this first function, how can I do this? I do not know how to successfully transfer the stream.

def endThread(thread):
    thread.exit()

Thank!

+4
source share
1 answer

This issue is almost a FAQ material.

To summarize, it is not possible to disable a stream from the outside. You can, of course, pass the stream object to any function you want, but there are no kill and exit calls in the stream library.

There are more or less two different ways around this, depending on what your thread is doing.

- , . : Thread Python? " ", .

, . -, -, , - . - -, , , N , .

- . . , . , .

-, , , , , , , -, .

+2

Source: https://habr.com/ru/post/1695138/


All Articles