mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-02 18:51:31 +08:00
docs(dirty): clarify application initialization sequence
This commit is contained in:
parent
c914f336b8
commit
9b0e87deb8
@ -136,10 +136,27 @@ class MLApp(DirtyApp):
|
|||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
|--------|-------------|
|
|--------|-------------|
|
||||||
| `init()` | Called once when dirty worker starts. Load resources here. |
|
| `init()` | Called once when dirty worker starts, after instantiation. Load resources here. |
|
||||||
| `__call__(action, *args, **kwargs)` | Handle requests from HTTP workers. |
|
| `__call__(action, *args, **kwargs)` | Handle requests from HTTP workers. |
|
||||||
| `close()` | Called when dirty worker shuts down. Cleanup resources. |
|
| `close()` | Called when dirty worker shuts down. Cleanup resources. |
|
||||||
|
|
||||||
|
### Initialization Sequence
|
||||||
|
|
||||||
|
When a dirty worker starts, initialization happens in this order:
|
||||||
|
|
||||||
|
1. **Fork** - Worker process is forked from dirty arbiter
|
||||||
|
2. **`dirty_post_fork(arbiter, worker)`** - Hook called immediately after fork
|
||||||
|
3. **App instantiation** - Each dirty app class is instantiated (`__init__`)
|
||||||
|
4. **`app.init()`** - Called for each app after instantiation (load models, resources)
|
||||||
|
5. **`dirty_worker_init(worker)`** - Hook called after ALL apps are initialized
|
||||||
|
6. **Run loop** - Worker starts accepting requests from HTTP workers
|
||||||
|
|
||||||
|
This means:
|
||||||
|
|
||||||
|
- Use `__init__` for basic setup (initialize empty containers, store config)
|
||||||
|
- Use `init()` for heavy loading (ML models, database connections, large files)
|
||||||
|
- The `dirty_worker_init` hook fires only after all apps have completed their `init()` calls
|
||||||
|
|
||||||
## Using from HTTP Workers
|
## Using from HTTP Workers
|
||||||
|
|
||||||
### Sync Workers (sync, gthread)
|
### Sync Workers (sync, gthread)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user