Ad
Failed To Import Multiprocessing Queue Object In Python3.6
I was using multiprocessing library in python. I have python 3.6. Whenever i try to create the multiprocessing. Queue() object i get an error.
My code looks like:
import multiprocessing
def square(arr,q):
for i in arr:
q.put(i*i)
arr=[1,2,3,4,5,6]
q=multiprocessing.Queue()
p1=multiprocessing.Process(target=square,args=(arr,q,))
p1.start()
p1.join()
result=[]
while q.empty() is False:
result.append(q.get())
print(result)
and error is :
Traceback (most recent call last):
File "qu.py", line 9, in <module>
q=multiprocessing.Queue()
File "/usr/lib/python3.6/multiprocessing/context.py", line 101, in Queue
from .queues import Queue
File "/usr/lib/python3.6/multiprocessing/queues.py", line 20, in <module>
from queue import Empty, Full
File "/home/vivek/Desktop/code/par/queue.py", line 11, in <module>
q=Queue()
File "/usr/lib/python3.6/multiprocessing/context.py", line 101, in Queue
from .queues import Queue
ImportError: cannot import name 'Queue'
Ad
Answer
As you can see in the import chain listed in the error traceback, Python is trying to import the Queue
definition from:
/home/vivek/Desktop/code/par/queue.py
This indicates you have somehow broken Python import logic as usually it prioritizes modules in /lib
/usr/lib
folders. This usually happens if you set your custom PYTHONPATH
environment variable or if you mess with module variables such as sys.path
.
Quick fix is to rename your file from queue.py
to something else.
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad