python-trio / purerpc

Native, async Python gRPC client and server implementation supporting asyncio, uvloop, and trio
Apache License 2.0
217 stars 15 forks source link

CI: macos target hangs during pytest #39

Open belm0 opened 1 year ago

belm0 commented 1 year ago

https://github.com/python-trio/purerpc/actions/runs/4158772667/jobs/7194217372

belm0 commented 1 year ago

presumably related to this log:

objc[2865]: +[__NSTimeZone initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

I couldn't naively reproduce it locally.

belm0 commented 1 year ago

It appears to be coming from grpc, but is not considered a grpc bug per se. It generally falls under "don't use os.fork() on macOS".

https://github.com/grpc/grpc/issues/31240

belm0 commented 1 year ago

We could disable the mac safeguard with OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES (see https://hynek.me/til/rq-macos/)

Recent Python versions don't use fork() on macOS by default, but I had the tests opt-in to it previously (9b59b66) due to another issue:

# work around pickle issue on macOS
if sys.platform == 'darwin':
    multiprocessing = multiprocessing.get_context('fork')
belm0 commented 1 year ago

OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES does not seem to work. I tried setting it both from the test module, and from the pytest invocation.

belm0 commented 1 year ago

The best way to resolve this, though it needs significant test refactoring:

# TODO: there is no reason to run the server as a separate process...
#   just use serve_async().