【发布时间】:2018-04-02 23:30:21
【问题描述】:
代码是:
from multiprocessing import Pool
import socket
target = 'hackthissite.org'
list1 = []
def f(port):
s = socket.socket()
try:
con = s.connect((target,port)
print("Success:",port)
s.close()
except:
print("Didn't work:",port)
s.close()
pass
#This function creates a list to iterate through for the map function
def port_list():
port_range = int(input("How many ports would you like to scan?"))
for x in range(1, port_range + 1):
list1.append(x)
if __name__ == '__main__':
port_list()
with Pool(2) as p:
p.map(f,list1)
print("Done")
无论池中有多少端口或工人,它都会给我: 调试适配器进程意外终止
但是,如果我使用 p.map(f,(80,)) 手动传递我想要的端口,它就可以工作 100% 没问题。出于某种原因,传递给它一个相对较大的列表,例如 range(1,80) 并使用任意数量的进程杀死它?顺便说一句,这是在 VS Code 中。
【问题讨论】:
-
“调试适配器进程已意外终止”听起来 VS Code 的调试功能在子进程中遇到了问题。如果您在没有 VS Code 的调试器的情况下运行,您是否尝试过?
标签: python-3.x python-multiprocessing port-scanning