Here is the code:
import multiprocessing as mp
with open(“input.txt”) as f:
f.seek(lineByte) # move lineByte positions to put the pointer there
line = f.readline()
pool = mp.Pool(mp.cpu_count())
if name == ‘main’:
with open("./test.txt",“rb”) as f:
nextLineByte = f.tell() # current position of the pointer
for line in f:
jobs.append( pool.apply_async(process_wrapper,(nextLineByte)) )
nextLineByte = f.tell()
#wait for all jobs to finish
for job in jobs:
After running, I got this error message as the following.
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.
Any comments are greatly appreciated.