我发现open
用python阻塞了。这是我的代码
import concurrent.futures
import os
import time
import logging
logging.basicConfig(level=logging.DEBUG)
def test(n1,n2,n3):
f = open(os.path.join('/Users/zhaodachuan/Downloads/test/',str(n1*n2*n3)+".txt"),"w+")
f.write("123")
time.sleep(1)
f.close()
return
list1 = list(range(4))
if __name__ == "__main__":
with concurrent.futures.ProcessPoolExecutor(4) as executor:
start = time.time()
for v in list1:
#test(v+1,v+2,v+3)
executor.submit(test(v+1,v+2,v+3))
print(time.time()-start)
完成它需要4秒钟,而我预计时间是1秒钟。我应该怎么做?