How to exit the entire application from a Python thread?

后端 未结 4 1400
醉酒成梦
醉酒成梦 2020-11-29 00:53

How can I exit my entire Python application from one of its threads? sys.exit() only terminates the thread in which it is called, so that is no help.

I w

4条回答
  •  Happy的楠姐
    2020-11-29 01:18

    The easiest way to exit the whole program is, we should terminate the program by using the process id (pid).

    import os
    import psutil
    
    current_system_pid = os.getpid()
    
    ThisSystem = psutil.Process(current_system_pid)
    ThisSystem.terminate()
    

    To install psutl:- "pip install psutil"

提交回复
热议问题