Python - Can't kill main thread with KeyboardInterrupt

前端 未结 2 1014
礼貌的吻别
礼貌的吻别 2020-12-17 17:26

I\'m making a simple multi-threaded port scanner. It scans all ports on host and returns open ports. The trouble is interrupting the scan. It take a lot of time for a scan t

相关标签:
2条回答
  • 2020-12-17 17:37

    You made your threads daemons already, but you need to keep your main thread alive while daemon threads are there, there's how to do that: Cannot kill Python script with Ctrl-C

    0 讨论(0)
  • 2020-12-17 17:42

    When you create the threads add them to a list of running threads and when dealing with ctrl-C send a kill signal to each thread on the list. That way you are actively cleaning up rather than relying on it being done for you.

    0 讨论(0)
提交回复
热议问题