[PATCH 3 of 4 V2] chgcache: implement the background preloading thread

Yuya Nishihara yuya at tcha.org
Sun Mar 5 03:12:24 EST 2017


On Thu, 2 Mar 2017 13:32:23 -0800, Jun Wu wrote:
> Excerpts from Yuya Nishihara's message of 2017-03-03 00:51:12 +0900:
> > I hope so, but googling "fork thread" or "fork thread python" made me feel
> > bad. I haven't read them carefully, but they seemed to say "don't do it."
> 
> Good catch!
> 
> I had a look at CPython source code. The most related function is
> PyOS_AfterFork(void), which will be executed by the child. It does not
> handle all lock issues (like malloc() in libc).
> 
> I think we can use os.fork() in master and avoid threading to solve the
> issue:
> 
>   worker              master        forked master
>     | send(repopath) -> |
>                         | fork() -----> |
>                                         | preload() 
>                                         | replace master's socket
>     | connect() ----------------------> |
> 
> This solves other problems - like parsers.c has some slow functions that may
> block accept().

Hmm, that seems relatively simple and worth trying. We might have to rewind
stack before fork() so the forked master wouldn't end up exhausting Python
stack.


More information about the Mercurial-devel mailing list