#974

Allow to specify the tokio runtime threads

Opengi0baroopened 24d ago

Monty launches its tokio runtime with its default number of threads (cpu cores) and the only way nowadays to override such value is to rely on the TOKIO_WORKER_THREADS environment variable, which is also shared by any other tokio runtime running.

For projects like PiDrei that want to fully-control their overall threads, the only way to customize Monty's tokio threads is to temporarily override that environment variable the first time they initialize Monty: https://github.com/gi0baro/pidrei/blob/master/packages/codemode/pidrei_codemode/runtime/pool.py#L48-L57.

It would be nice to have an argument on the Monty class init to set a specific number of tokio threads (eg: a runtime_threads: int | None)

Activity

2
samuelcolvin24d ago

makes sense. PR welcome.

Parikalp-Bhardwaj23d ago

I have opened #995 with an implementation for this.

It adds runtime_threads to Monty, AsyncMonty, and AsyncMontyWebsocket, while keeping the existing lazy runtime behavior when the option isn’t provided.

I also handled the shared Tokio runtime case so a conflicting thread count returns an error instead of being silently ignored.

Would appreciate any feedback on the approach.