线程 - shell 卡在程序退出处

threading - shell stuck at program exit

我已经基于python-nmap 库编写了一个网络映射器。 我有一个列表,其中包含要扫描的所有 IP 地址。 从 htop 我看到所有生成的线程都在程序退出之前终止。

程序执行完成后,shell(我用的是bash)卡住了。当我写东西时,它不会显示我在写什么。如果我写 'reset'(即使我看不到),shell 会正确重新初始化。

怎么了?

我 运行 使用 Python 3.7.3 安装在 Debian 10 Buster 发行版上的脚本。

下面是一段代码。

#!/usr/bin/env python3

hosts_up = ['192.168.0.5', '192.168.0.6', '192.168.0.8']
fingerprinting_threads = []
nm_obj = nmap.PortScanner()

# Callback
def fingerprintAndSaveToDb(host_to_fingerprint):
    scan_result = nm_obj.scan(hosts=host_to_fingerprint, ports=None, arguments=' -sN -Pn')
    print(scan_result)

# Main flow
for single_host_up in hosts_up:
    t = threading.Thread(target=fingerprintAndSaveToDb, args=(single_host_up,))
    t.start()
    fingerprinting_threads.append(t)

print("Joining")
for single_thread in fingerprinting_threads:
    single_thread.join()
print("Joint")

# sys.exit() - It could be unuseful

将 shell 从 bash 更改为 zsh 问题已解决。