Why am I getting an import error upon importing multiprocessing?
Asked Answered
A

2

6

I have a script which requires multiprocessing. What I found from this script is that there is a problem with the multiprocessing module. To test this theory, I copied and pasted

from multiprocessing import Process

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

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

into a test script and received the following traceback

Traceback (most recent call last):
  File "a.py", line 1, in <module>
    from multiprocessing import Process
  File "/usr/lib64/python3.3/multiprocessing/__init__.py", line 40, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "/usr/lib64/python3.3/multiprocessing/util.py", line 16, in <module>
    import threading        # we want threading to install it's
  File "/usr/lib64/python3.3/threading.py", line 11, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib64/python3.3/traceback.py", line 3, in <module>
    import linecache
  File "/usr/lib64/python3.3/linecache.py", line 10, in <module>
    import tokenize
  File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
    from token import *
  File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
    from django.conf import settings
  File "/usr/lib/python3.3/site-packages/django/conf/__init__.py", line 9, in <module>
    import logging
  File "/usr/lib64/python3.3/logging/__init__.py", line 195, in <module>
    _lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'

Also, I am running fedora 18 64-bit on a quad core ivy bridge. Why am I receiving this traceback error?

Suggestion

Here is what happens when I run RLock

$ python3
>>> import threading
>>> threading.RLock()
<_thread.RLock owner=0 count=0>
>>> 
Askins answered 12/8, 2013 at 17:22 Comment(1)
Try to import threading, on iPython or anything similar, and try to call the RLock()... Just to see what happens...Godsend
W
11
File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
    from token import *
File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
    from django.conf import settings

Your /home/lucas/Server/ClinApp/weblabs/utils/token.py script is being imported instead of the standard python 'token.py'. Its got a bug in it or it simply shouldn.t be imported as a top level script. You probably have /home/lucas/Server/ClinApp/weblabs/utils/ in your python path in some way.

Generally, its not a good idea to name python scripts after builtin scripts.

Wellthoughtof answered 12/8, 2013 at 17:29 Comment(0)
P
0

After you rename token.py to something else (get_token.py), remember to delete token.pyc in your local working directory. Or else, you will continue to get the Traceback error message you listed above.

Pasco answered 25/8, 2017 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.