[英]Does the calling stack in python's shared between the threads or the processes in multithreading and multiprocessing respectively?
I am writing a code in python which includes some multiprocessing
and multithreading
. 我正在用python写代码,其中包括一些
multiprocessing
和multithreading
。
My question is: Does the threads or the processes share the same call stack? 我的问题是: 线程或进程共享相同的调用堆栈吗?
I am using the inspect
module and I'm afraid that it will return me the wrong value in inspect.stack()
. 我正在使用
inspect
模块,恐怕它将在inspect.stack()
返回错误的值。
No they don't, subprocesses get forked/spawned as separate entities so each Process starts off effectively as a completely new Python instance. 不,它们不是,子流程作为单独的实体被派生/生成,因此每个流程都作为一个全新的Python实例有效地启动。
Python hides away some of the nastiness of that by transparently pickling/unpickling data to be transferred between processes but they all get their own stack, their own GIL and all that goes with it. Python通过透明地腌制/取消腌制要在进程之间传输的数据来掩盖其中的某些麻烦,但是它们都拥有自己的堆栈,自己的GIL以及随之而来的所有内容。
Multithreading is a different story - threads do share the underlying stack but Python partitions them to appear as each has their own stack so inspect.stack()
results can be confusing/unpredictable.. 多线程是另一
inspect.stack()
-线程确实共享底层堆栈,但是Python对它们进行分区以使其显示为每个都有自己的堆栈,因此inspect.stack()
结果可能令人困惑/无法预测。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.