Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 uvicorn 或者 gunicorn 启用多 process(多个 worker)的问题 #14

Open
fxconfig opened this issue Jan 11, 2025 · 0 comments

Comments

@fxconfig
Copy link

uvicorn worker = 4
会有五个进程,主进程 uvicorn ,四个子进程 app
每个进程都会有自己的全局对象,
所以,

  1. 如果使用 python run.py , 在 run.py 内写 uvicorn 命令,则最好不要把 全局变量放在 run.py
  2. 要启动 (唯一)定时器,RLock 是不够的,它只是进程内对各个线程之间的锁,还需要外部辅助,filelock 或者 redis lock 或者 db lock
    在 lifespan 或者 onstartup 里面,得加锁
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant