Skip to main content
 首页 » 编程设计

python3错误,无法导入名称 'SimpleQueue'

2024年10月24日12birdshome

#!/usr/bin/env python3 
 
import logging; logging.basicConfig(level=logging.INFO) 
 
import asyncio, os, json, time 
from datetime import datetime 
 
from aiohttp import web 
 
def index(request): 
    return web.Response(body=b'<h1>Awesome</h1>') 
 
@asyncio.coroutine 
def init(loop): 
    app = web.Application(loop=loop) 
    app.router.add_route('GET', '/', index) 
    srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) 
    logging.info('server started at http://127.0.0.1:9000...') 
    return srv 
 
loop = asyncio.get_event_loop() 
loop.run_until_complete(init(loop)) 
loop.run_forever() 

Process (28411) start... I (28411) just created a child process (28412). I am child process (28412) and my parent is 28411. Traceback (most recent call last): File "webApp.py", line 5, in import asyncio, os, json, time File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/init.py", line 21, in Traceback (most recent call last): File "webApp.py", line 5, in import asyncio, os, json, time File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/init.py", line 21, in from .base_events import * File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 18, in from .base_events import * File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/asyncio/base_events.py", line 18, in import concurrent.futures File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/init.py", line 17, in import concurrent.futures File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/init.py", line 17, in from concurrent.futures.process import ProcessPoolExecutor File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/process.py", line 54, in from concurrent.futures.process import ProcessPoolExecutor File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/concurrent/futures/process.py", line 54, in from multiprocessing import SimpleQueue from multiprocessing import SimpleQueue ImportError: cannot import name 'SimpleQueue' ImportError: cannot import name 'SimpleQueue'

请您参考如下方法:

simpleQueue 的 API 似乎已经改变。

在 python3.3 中,它位于 multiprocessing.SimpleQueue 中(参见文档 1 )

在 python3.2 中,它在 multiprocessing.queues.SimpleQueue 中找到(参见文档 2 )

您可能运行的 python 版本早于 3.2,但代码是为较新版本 (>= 3.3) 编写的。您可以尝试修改库以使用旧的导入或升级您的 python 版本。