아래 예제를 사용하여 Asyn인지 여부를 확인했습니다. 그러나 그것은 작동하지 않는 것 같습니다. 아래 코드를 사용했습니다.Python asyncio-motor가 비동기식으로 작동하지 않음
import asyncio
import time
from motor.motor_asyncio import AsyncIOMotorClient
async def get_all_from_coll(col):
client = AsyncIOMotorClient("localhost", 27017)
db = client.project_matrix
cursor = db[col].find()
time.sleep(5)
for document in await cursor.to_list(length=100):
print(document)
loop = asyncio.get_event_loop()
print('001')
loop.run_until_complete(get_all_from_coll('users'))
print('002')
내가
>>>001
>>>{'_id': ObjectId('58d9b178d011b53743d44413'), 'username': 'test1', 'password': 'test', '__v': 0}
>>>{'_id': ObjectId('58d9b229d011b53743d44414'), 'username': 'test2', 'password': 'test', '__v': 0}
>>>002
내가 뭔가 잘못하고 있는가 위해 아래에 출력을 얻고있다
?
'time.sleep'이 (가) 차단 중입니다. 대신에'asyncio.sleep'을 사용하십시오. – dirn