You are not logged in.

#1 2011-09-18 11:08:23

Pajaro
Member
Registered: 2004-04-21
Posts: 884

python2 multiprocessing ImportError

When I try to work with multiprocessing with python2 I keep getting ImportError. So I tried to run multiprocessing test...

$ python2 /usr/lib/python2.7/test/test_multiprocessing.py

...and it worked well. So I made a copy of test_multiprocessing.py to another folder and I got this:

Traceback (most recent call last):
  File "test_multiprocessing.py", line 20, in <module>
    _multiprocessing = test_support.import_module('_multiprocessing')
  File "/usr/lib/python2.7/test/test_support.py", line 79, in import_module
    return importlib.import_module(name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/franki/multiprocessing.py", line 27, in <module>
    test_support.import_module('multiprocessing.synchronize')
  File "/usr/lib/python2.7/test/test_support.py", line 81, in import_module
    raise unittest.SkipTest(str(msg))
unittest.case.SkipTest: No module named synchronize

According to the python documentation, synchronize fails to import if your operating system does not support a shared semaphore, but then the test wouldn't run either.

What am I missing?

Last edited by Pajaro (2011-09-18 11:08:42)

Offline

#2 2011-09-18 12:41:00

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: python2 multiprocessing ImportError

Why don't you show the actual ImportError which you're getting while trying to work with multiprocessing?

Offline

#3 2011-09-19 10:02:06

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: python2 multiprocessing ImportError

This is the code from the first example in the python documentation http://docs.python.org/library/multiprocessing.html

from multiprocessing import Process

def f(name):
    print 'hello', name

if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()

and it outputs:

$ python2 multiprocessing.py
Traceback (most recent call last):
  File "multiprocessing.py", line 1, in <module>
    from multiprocessing import Process
  File "/home/franki/multiprocessing.py", line 1, in <module>
    from multiprocessing import Process
ImportError: cannot import name Process

Offline

#4 2011-09-19 10:32:08

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: python2 multiprocessing ImportError

@Pajaro:  Do the following:

mv multiprocessing.py foo.py
rm *.pyc
python foo.py

Next time please read the error message instead of trying to mess around with some totally unrelated testsuite…

Last edited by lunar (2011-09-19 10:34:14)

Offline

#5 2011-09-21 23:32:35

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: python2 multiprocessing ImportError

Thank you.

PS: I read the error many times. It is lack of experience understanding python errors.

Offline

#6 2011-09-22 11:36:10

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,097

Re: python2 multiprocessing ImportError

Short story: Don't name your .py files the same as some module in stdlib etc. Also, absolute imports ftw.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#7 2011-09-22 13:28:20

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: python2 multiprocessing ImportError

Yes, I know. I do intentional overrides some times. From my experience, reporting infinite recursion would have been more clear, since self-importing a file doesn't make much sense, because the scope is in the file, so you can refer to self defined elements with no need for imports, and, also, for overrides you have the as keyword (import [somthing] as [something_else]).

Offline

Board footer

Powered by FluxBB