简体   繁体   中英

Does Python release Global Interneter Lock when a C bindings block?

I have a some C bindings that do lot of disk access.

Is the GIL released when the C library blocks on disk access?

C libraries that run as part of a Python program can, as you suggest, release the GIL before performing extensive computations without needing access to Python objects, and doing so will indeed allow more parallelism by allowing I/O to continue in the background. Unless the library was intended for the Python environment, however, it probably won't, and even if it was there's no guarantee it does release the GIL.

If the libraries weren't specifically designed for Python they won't release the GIL. In that case you can achieve a lot by wrapping the appropriate functions in C wrappers that manage the GIL.

If the libraries weren't specifically for Python, or if the GIL isn't mentioned in their documentation, the only way to be sure would be to examine the source code. Your C code can manipulate the GIL using functions defined in Python's C API .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM