Поцаны, не занимайтесь фигней короче, используйте в этом случае воркеров
Код воркера
async def worker(*, user_id):
print('start')
await asyncio.sleep(10)
print(user_id)
async def main():
connection = await connect_robust("amqp://guest:guest@127.0.0.1/")
# Creating channel
channel = await connection.channel()
await channel.set_qos(prefetch_count=1)
master = Master(channel)
await master.create_worker("my_task_name", worker, auto_delete=True)
return connection
Код продюсера
async def run_rabbitmq_queue(user_id):
connection = await connect_robust("amqp://guest:guest@127.0.0.1/")
async with connection:
# Creating channel
channel = await connection.channel()
master = Master(channel)
# Creates tasks by proxy object
await master.proxy.my_task_name(user_id=user_id)
# Or using create_task method
await master.create_task(
"my_task_name", kwargs=dict(user_id=user_id)
)
print('!')