Access db from forked process

I am facing in a strange behavior using python api to access fdb. This is based on gunicorn which forks a worker process. I open the database from main then I try to uses it from forked process then it hangs.

I produced in a small script this behavior. I debugged and found that it stucks in semaphore.acquire() in fdb/impl.py in function block_until_ready.

Here is a buggy script that reproduces, any help is welcome. Thank you



import fdb

fdb.api_version(630)

from multiprocessing import Process


db = fdb.open('/etc/local/foundationdb/fdb.cluster')

db[b'u'] = b'v'

print( db[b'u'])

def f(name, db):
    #import pdb; pdb.set_trace()
    print('hello', name, db)
    db[b'z'] = b'w'
    print(db[b'z'])

if __name__ == '__main__':
    p = Process(target=f, args=('bob',db))
    p.start()
    p.join()

See the post below for a little discussion of this. The conclusion there was that you’ll need to connect to FDB after you fork rather than before in order for the client network thread to work properly.

It was also my independent conclusion after session of debug. In fact I use Gunicorn which forks a new process.
So I do init in forked process. Even my python module is loaded before. This has some drawbacks but works.

Thank you