在 Cython 中释放 GIL 的危险?

Dangers of Releasing the GIL in Cython?

如果我选择在 Cython 脚本中发布 GIL,我需要考虑哪些因素?

在 Cython 程序中释放 GIL 是否有任何额外的危险或风险?

另外,如何指定要生成的线程数?

If I choose to release the GIL in a Cython script what considerations do I have to make?

Are there any added dangers or risk to releasing the GIL in a Cython program?

您不能安全地对 Python 对象做任何有趣的事情。你不能安全地做任何接触你的对象数据的事情,而不知道它是安全的(可能有你自己的锁)。

https://docs.python.org/2/c-api/init.html#thread-state-and-the-global-interpreter-lock 将提供一些信息。

Also how do I specify the number of threads to spawn?

创建线程是完全独立的。您可以使用 threading 模块执行此操作,也可以使用其他任何方式执行此操作。