Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复python中的“缩进错误:意外缩进”错误_Python_Python 3.x_Python 2.7_Multiprocessing_Subprocess - Fatal编程技术网

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

如何修复python中的“缩进错误:意外缩进”错误,python,python-3.x,python-2.7,multiprocessing,subprocess,Python,Python 3.x,Python 2.7,Multiprocessing,Subprocess,它给了我以下的错误 File "parallel-1 (2).py, line 274 p1 = multiprocessing.Process(target=find_nearest, args=(array[idx],)) IndentationError: unexpected indent 你应该这样做。在python中避免缩进,除非循环或条件构造需要缩进 #here the multiprocessing process starts procs = [] p1 = multi

它给了我以下的错误

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

你应该这样做。在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!")

通过不这样缩进来修复错误。这里的所有东西都应该排在左边,可能是
#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!")