我已经试着让我的代码运行了很多天,
我有一个文本文件,用9GB的"latin-1"编码->;737 022 387行,每行包含一个字符串.
我想读取每一行并在http PUT请求中发送它们,该请求等待响应,如果响应是200或400,则返回TRUE或FALSE
首先,我用3秒钟的睡眠模拟我的PUT请求.
这段代码将我的字符串拆分为字符,我不知道为什么...
from multiprocessing import Pool
from time import sleep
def process_line(line):
sleep(3)
print(line)
return True
if __name__ == "__main__":
pool = Pool(2)
peon = open(r'D:\txtFile',encoding="latin-1")
for line in peon:
res = pool.map(process_line,line )
print(res)
这个give error:TypeError:process_line()接受1个位置参数,但给出了17个
import multiprocessing
from multiprocessing import Pool
from time import sleep
def process_line(line):
sleep(3)
print(line)
return True
if __name__ == "__main__":
pool = Pool(2)
with open(r"d:\txtFile",encoding="latin-1") as file:
res = pool.apply(process_line,file.readline() )
print(res)
那就是:让电脑崩溃
from multiprocessing import Pool
from time import sleep
def process_line(line):
sleep(3)
print(line)
return True
if __name__ == "__main__":
pool = Pool(2)
peon = open(r'D:\txtFile',encoding="latin-1")
for line in peon:
res = pool.map(process_line,peon )
print(res)