在后台执行几个脚本
我有一个页面,用户选择Python脚本,然后该脚本执行。 我的问题是,有些脚本需要一段时间才能执行(最高30m),因此我想在后台运行它们,而用户仍然可以在网站上导航。
我尝试使用芹菜,但是当我在Windows上,我做得比使用- pool = solo
,虽然允许用户做其他事情,但只能为一个用户做其他事情一次。
我还看到了此线程在搜索解决方案时,但是没有设法真正了解它的工作原理或如何实施,也没有确定它是否真的在回答我的问题...
所以这是我的问题:我如何在芹菜上拥有多个线程/多个过程在Windows 上?或者,如果有另一种方式,我如何在后台同时执行多个任务?
I have a page where the user selects a Python script, and then this script executes.
My issue is that some scripts take a while to execute (up to 30m) so I'd like to run them in the background while the user can still navigate on the website.
I tried to use Celery but as I'm on Windows I couldn't do better than using --pool=solo
which, while allowing the user to do something else, can only do so for one user at a time.
I also saw this thread while searching for a solution, but didn't manage to really understand how it worked nor how to implement it, as well as determine if it was really answering my problem...
So here is my question : how can I have multiple thread/multiple processes on Celery while on Windows ? Or if there's another way, how can I execute several tasks simultaneously in the background ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否确定了您的慢脚本是否属于CPU结合任务或I/O绑定任务?
如果它们是I/O绑定,则可以根据策略1在来自DistributatePython.com的博客
但是,如果它们绑定了CPU,您可能必须考虑使用诸如专用芹菜盒(或Windows Docker容器)之类的方式来解决芹菜台球问题。通过设置环境变量(
forked_by_multiprocessing = 1
),基于策略2 来自distributedpython.com的博客Have you identified whether your slow scripts belong to CPU-bound tasks or I/O bound tasks?
if they're I/O bound, you can use eventlet and gevent based on Strategy 1 in the blog from distributedpython.com
but if they're CPU bound, you may have to think of using the ways like a dedicated Celery windows box (or windows Docker container) to workaround Celery billiard issue on Windows by setting the environment variable (
FORKED_BY_MULTIPROCESSING=1
) based on Strategy 2 in the blog from distributedpython.com