Terminate a multi-thread python program

前端 未结 7 770
猫巷女王i
猫巷女王i 2020-12-02 16:17

How to make a multi-thread python program response to Ctrl+C key event?

Edit: The code is like this:

import threading
current = 0

c         


        
7条回答
  •  醉梦人生
    2020-12-02 17:02

    You can always set your threads to "daemon" threads like:

    t.daemon = True
    t.start()
    

    And whenever the main thread dies all threads will die with it.

    http://www.regexprn.com/2010/05/killing-multithreaded-python-programs.html

提交回复
热议问题