简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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