bblfsh / python-client

Babelfish Python client
https://doc.bblf.sh/using-babelfish/clients.html
Apache License 2.0
16 stars 20 forks source link

bblfsh.decode hangs with multiprocessing #171

Open vmarkovtsev opened 5 years ago

vmarkovtsev commented 5 years ago

The following code hangs:

import bblfsh

def decode(uast):
    return bblfsh.decode(uast).load()

uasts = [b"", b"", ...]  # protobuf bytes
pool = multiprocessing.Pool(multiprocessing.cpu_count())
pool.map(decode, uasts)

however this doesn't

def decode(uast):
    import bblfsh
    return bblfsh.decode(uast).load()

uasts = [b"", b"", ...]  # protobuf bytes
pool = multiprocessing.Pool(multiprocessing.cpu_count())
pool.map(decode, uasts)

The reason is likely because gRPC in Python infinitely sucks as always, and it manages to interfere with regular protobuf reading somehow. I wonder if there is a way to fix this.

We had to defer grpc loading in the past when we had similar problems.

creachadair commented 5 years ago

I think https://github.com/grpc/grpc/issues/16001 is likely to be relevant here. Specifically, this might explain why the deferred import appears to "help" in this case.