0

I've run into a bit of a wall here, so I'm going to do my best to explain the issue.

def playGames(jobQueue, ...):
  ....
  nextJob = jobQueue.get()
  ...

def runPool(fens, timesetting, ...):
  ...
  for fen in fens:
    jobQueue.put(Job(gamefen=fen, timecontrol=timesetting))
  ...

if __name__ == '__main__':
  Job = collections.namedtuple('Job', 'gamefen timecontrol')
  ...
  ...
  playGames(jobQueue, ...) # jobQueue is a multiprocess.Queue() object

After running this, the following error gets thrown.

"'module' object has no attribute 'Job'"

So I moved the Job = collections... line above the if name==main thing and it worked!

But, the way the code is written without the Job = collections... moved will work perfectly fine, on my Ubuntu system.

So Windows7 using python2.7.8 it does not work Ubuntu14 using python2.7.6 it does work Ubuntu14 using python3.4.3 it does work

I must be missing something here...

THE FULL TRACEBACK IS HERE :

Traceback (most recent call last):
  File "c:\Python27\lib\multiprocessing\process.py", line 258, in _bootstrap
    self.run()
  File "c:\Python27\lib\multiprocessing\process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "c:\Users\Andy\Desktop\Github\LucasZinc\Zinc.py", line 338, in play_games
    _job = jobQueue.get()
  File "c:\Python27\lib\multiprocessing\queues.py", line 117, in get
    res = self._recv()
AttributeError: 'module' object has no attribute 'Job'
AndrewGrant
  • 786
  • 7
  • 17

1 Answers1

1

On Windows, the implementation of multiprocessing places additional constraints on code - effectively what happens is a different python interpreter is started for each process, and then these new interpreters load the python code as non-main - so, to use Job, the non-main processes need to have Job defined outside the if __name__=='__main__' conditional statement. See heading 16.6.3.2 below https://docs.python.org/2/library/multiprocessing.html

  • Excellent. That reason makes a great deal of sense; It is nice to see the source for it. Thanks for your time! I will accept the answer once the time expires. – AndrewGrant Aug 01 '16 at 04:59