Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有一个模块可以在 Python 中抽象线程和多处理?我希望将来可以选择在它们之间切换。
threadingand模块已经为此使用了类似的multiprocessing接口。threading如果不支持,多处理实际上会退回到模块。
threading
multiprocessing
您可以使用import multiprocessing as somethingandimport threading as something在两个看不见的之间切换。
import multiprocessing as something
import threading as something
请注意,两者之间的数据共享是不同的,这可能会造成潜在的陷阱。正如jdi所指出的