如何修复 Python 中的" indentationError: unexpected indent "错误



它给我以下错误

File "parallel-1 (2).py, line 274 
  p1 = multiprocessing.Process(target=find_nearest, args=(array[idx],))
IndentationError: unexpected indent

#here the multiprocessing process starts
procs = []
    p1 = multiprocessing.Process(target=find_nearest, args=(array[idx],))
    procs.append(p1)
    p2 = multiprocessing.Process(target=find_nearest, args=(array[idx],))
    procs.append(p2)
    p3 = multiprocessing.Process(target=find_nearest, args=(array[idx],))
    procs.append(p3)
    p1.start()
    time.sleep(5)
    p2.start()
    time.sleep(5)
    p3.start()
    time.sleep(5)
    p1.join()
    p2.join()
    p3.join()
print("Done!")

这就是您应该做的。除非需要循环或条件构造,否则请避免在Python中缩进。

#here the multiprocessing process starts
procs = []
p1 = multiprocessing.Process(target=find_nearest, args=(array[idx],)) #you had indentation here and all lines below till p3 join statement
procs.append(p1)
p2 = multiprocessing.Process(target=find_nearest, args=(array[idx],))
procs.append(p2)
p3 = multiprocessing.Process(target=find_nearest, args=(array[idx],))
procs.append(p3)
p1.start()
time.sleep(5)
p2.start()
time.sleep(5)
p3.start()
time.sleep(5)
p1.join()
p2.join()
p3.join()
print("Done!")

相关内容

  • 没有找到相关文章

最新更新