简体   繁体   English

在Python中抽象化线程和多处理?

[英]Abstracting threading and multiprocessing in Python?

Is there a module that abstract threading and multiprocessing in Python? 是否有一个模块可以在Python中抽象化线程和多处理? I want to have an option of switching between them in future. 我希望将来可以选择在它们之间进行切换。

The threading and multiprocessing module already use a similar interface for this. threadingmultiprocessing模块已经为此使用了类似的接口。 The multiprocessing actually falls back to the threading module if it isn't supported. 如果不支持多处理,则实际上它会退回到threading模块。

You can use an import multiprocessing as something and import threading as something to switch between the two unseen. 您可以将import multiprocessing as somethingimport threading as something以在两个看不见的对象之间切换。

Note that data sharing between the two is different and this might create potential pitfalls. 请注意,两者之间的数据共享是不同的,这可能会导致潜在的陷阱。 As noted by jdi 如jdi所述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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