简体   繁体   English

python的调用堆栈是否分别在多线程和多处理的线程或进程之间共享?

[英]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写代码,其中包括一些multiprocessingmultithreading

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.

相关问题 在 python 多处理中的进程之间使用共享值终止循环 - Loop termination using shared value between the processes in python multiprocessing Python 多处理 - 在线程之间使用共享变量和管理器? - Python multiprocessing - Using shared variables with a manager between threads? Python Bottle应用程序中的类实例,它在线程/进程之间共享吗? - Class instance in Python Bottle application, is it shared between threads/processes? Python:关于多处理/多线程和共享资源的问题 - Python: Question about multiprocessing / multithreading and shared resources Gunicorn在多处理流程和工作人员之间共享内存 - Gunicorn shared memory between multiprocessing processes and workers 进程之间进行通信:Python多处理 - Communicating between Processes: Python Multiprocessing 为什么python多处理pickle对象在进程之间传递对象? - Why does python multiprocessing pickle objects to pass objects between processes? RawArray 未被进程修改为 Python 多处理的共享内存 - RawArray not modified by processes as shared memory for Python multiprocessing Python在线程和进程之间同步 - Python synchronise between threads and processes Python GIL 是由进程中的线程共享还是由所有进程中的所有线程共享? - Is the Python GIL shared by threads in a process or is it shared by all threads in all processes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM