I am having problems with code in the following format and assume that the error is to do with how I am trying to access the elements in each tuple.
from numberer import numberify
from sys import argv
infile=argv[1]
from multiprocessing import Pool
pool=Pool(15)
import os
def chunker(fob):
chunkbegin=0
filesize=os.stat(fob.name).st_size
while chunkbegin < filesize:
chunkend=chunkbegin+100000
fob.seek(chunkend)
fob.readline()
chunkend=fob.tell()
yield (chunkbegin,chunkend)
chunkbegin=chunkend
def run(tup, fob):
fob.seek(tup[0])
length=int(tup[1])-int(tup[0])
lines=fob.readlines(length)
for line in lines:
print(line)
fob=open(infile)
chunks=[x for x in chunker(fob)]
pool.map(run, (chunks, fob))
The exact error is:
Process ForkPoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.6/multiprocessing/pool.py", line 108, in worker
task = get()
File "/usr/lib/python3.6/multiprocessing/queues.py", line 337, in get
return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'run' on <module '__main__' from 'pretonumber.py'>
1) So when map function maps the tuples to function; I assume that these elements should be called as if they are ordinary tuples? IE with one index?
2) The element chunks that I am passing to the function run: is a list of tuples: chunks=[(0,100000),(100000,200000)....] as created by the generator chunker.
Thank you.