arq
arq copied to clipboard
Any example for how to start two workers in the same script
What i use:
async def main():
worker1.async_run() # code blocks here
worker2.async_run()
asyncio.run(main())
What i expected:
async def main():
worker1.async_run() # need something nonblocking here
worker2.async_run() # code blocks here
asyncio.run(main())
Any suggestions?
The same problem, when i need to start the workers in other async app. Where workers not a last instance that should be run.
It will be good if answers will not contain any code with loop, like loop.create_task() etc, till its bad practice to call event loop in main function.
Thx you!
Ps. I dont understand the need of WorkerSettings class in 1st example of docs. There is no workers that should use this class and specially no run() or async_run() in code to run any workers.
How to run blocking code is already documented here.
How to run blocking code is already documented here.
So, i should run workers via run_in_execuror()?
And moreover via simple worker.run()? Or how can i close connection manually after using async_run()?
Thx for help 😊
The documentation has a section on how to run the runner. Please read it through and make the examples work before you implement custom logic.
https://arq-docs.helpmanual.io/#simple-usage
arq demo.WorkerSettings
is described there. arq
is a command just like python
.
Can this be closed, @Soulbadguy54?
I still have no answer, but i do it via loop.create_task(worker.async_run()), because im not interesting in run my script via arq command.
The project is very heavy and should be run via python main.py where all services like aiohttp server, db connection, redis queue, parsers, etc should be run one by one. So, what is the right way to start it in async mod?
There’s a on_startup
setting that can handle all of this, so it sounds like your attacking the problem from the wrong angle.
Anyway, it’s a click app. This should help you.
@JonasKs's answer looks good.
More generally, this is not really an arq specific question, just an issue of how to run coroutines.