pythonnet / clr-loader

Loader for different .NET runtimes
MIT License
32 stars 22 forks source link

Deadlock calling pythonnet.set_runtime twice #64

Open sschukat opened 1 year ago

sschukat commented 1 year ago

With the update to delay the load of the runtime from 0.25 to 0.26 a deadlock occurs with following code

import pythonnet
pythonnet.set_runtime("coreclr")
pythonnet.set_runtime("coreclr")

This is explicit a problem of the core clr. We did not see that with .NET FF.

We tracked it down to https://github.com/pythonnet/clr-loader/blob/a88b6a1a0086278e3518f373487ae8819023cb2e/clr_loader/hostfxr.py#L135

this function deadlocks the second time called if https://github.com/pythonnet/clr-loader/blob/a88b6a1a0086278e3518f373487ae8819023cb2e/clr_loader/hostfxr.py#L146

was not called before.

filmor commented 1 year ago

Thank you for the report, I'll look into it. It's probably enough to force finishing up the initialization in set_runtime instead of keeping it in limbo until load is called.