python - 调用嵌入式Python模块时,是否切换了线程?

标签 python c multithreading pthreads

我有一个 C 程序,我在其中调用 Linux 机器上的嵌入式 Python 模块,使用:

Py_Initialize();

    PyObject_CallFunction(PyFun)

Py_Finalize();

我的问题是:python 函数是否仍会与 C 函数在同一线程中运行?我该如何检查?

我在 python 中使用 thread.get_ident() 并在 C 中使用 pthread_self() 来打印线程 ID。但我不确定它们是否意味着同一件事。

最佳答案

我尝试在 Python 模块执行期间从包装的 C 函数打印 pthread_self()。 1. 等同于在调用python模型之前调用pthread_self()。 2. python中的两个pthread_self()不等于thread.get_ident()。

所以我猜 1.在同一个线程中。 2. pthread_self() 和thread.get_ident() 有很大的不同。

关于python - 调用嵌入式Python模块时,是否切换了线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32511737/

相关文章:

c++ - 带有插入符号操作的字符 XOR

c - 对 URL 字符进行编码

python - Pandas:使用 bool 掩码替换多列的值

python - 如何舍入pydatatable中的 float 值?

c - typedef 结构错误。 '*' token 之前

multithreading - 如何在 Windows 操作系统上模拟 ThreadX 应用程序

php - PHP 中的多线程编程以避免运行时限制

java - 通过运行对象的同步方法来获取对象的锁

C# Nmath 到 Python SciPy

python - 将 utf 转换为它们的真实符号