opendal icon indicating copy to clipboard operation
opendal copied to clipboard

opendal python could hang while using with multiprocess

Open Zheaoli opened this issue 1 year ago • 5 comments

Zheaoli avatar Nov 16 '24 15:11 Zheaoli

This is a tracking issue.

Zheaoli avatar Nov 16 '24 15:11 Zheaoli

Is there a way to reproduce this issue? Maybe @TennyZhuang can share more details here?

Xuanwo avatar Nov 16 '24 15:11 Xuanwo

I write some scripts to reproduce it, but failed, can you offer more detail for it?

yihong0618 avatar Mar 29 '25 11:03 yihong0618

This is related to https://github.com/tokio-rs/tokio/issues/4301.

The best we can do is return an error when Python users attempt to use fork.

This issue isn't limited to OpenDAL—it's relevant to all Python crates that depend on Tokio.

Xuanwo avatar Mar 30 '25 06:03 Xuanwo

One such use case is for pre-forking servers running multiple worker processes. Many Python and Ruby webservers are pre-fork servers, e.g., Gunicorn, Puma for saving memory. A typical timeline for such servers:

  1. A web server runs as a master process, loading web application into memory.
  2. The master process forks itself, utilizing Copy-on-Write to save memory for child worker processes.

There is also a "refork" server which reaps worker processes and forks a warm worker process. When working with third-party libraries, web application developers have to releases resources during fork, e.g.,

  • tokio resources
  • locks and mutex
  • file descriptors

Another question is if it's wrong to open an Operator while forking. A service's existing caches, listers and async tasks are useless to another process.

erickguan avatar Jun 20 '25 16:06 erickguan