简体   繁体   English

如何修复“ indentationError:意外缩进” python中的错误

[英]how to fix“ indentationError: unexpected indent ” error in python

it gives me the following error 它给我以下错误

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!")

That's how you should do it. 那就是你应该怎么做。 Avoid indentation in python unless required as in case of loop or conditional constructs. 除非在循环或条件构造的情况下需要,否则避免在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!")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM