- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
根据documentation ThreadPoolExecutor
If
max_workers
isNone
or not given, it will default to the number of processors on the machine.
如果我不给它设置这样的值
ThreadPoolExecutor(max_workers=None)
如果我的值很低 (2) 会不会影响性能?python 是否已经为 None 值分配了所有 CPU 进程,还是仅为带有数字的值分配了 2 个进程?
最佳答案
首先,您似乎在链接中引用了文档的错误部分,即针对进程而非线程的部分。 one for concurrent.futures.ThreadPoolExecutor
状态:
Changed in version 3.5: If
max_workers
isNone
or not given, it will default to the number of processors on the machine, multiplied by 5, assuming that ThreadPoolExecutor is often used to overlap I/O instead of CPU work and the number of workers should be higher than the number of workers for ProcessPoolExecutor.
由于您使用的是线程,而不是进程,因此假设您的应用程序是 IO 绑定(bind)的,而不是 CPU 绑定(bind)的,并且您将其用于 concurrency, not parallelism .您使用的线程越多,您获得的并发性就越高(在一定程度上),但您获得的 CPU 周期就越少(因为会有上下文切换)。您必须在典型的工作负载下测试您的应用程序,以了解最适合您的方法。对此没有普遍最优的解决方案。
关于Python 多线程 max_workers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40492894/
根据documentation ThreadPoolExecutor 的 If max_workers is None or not given, it will default to the num
我在网上找了好久。但没有用。请帮助或尝试给我一些如何实现这一目标的想法。 当我使用python模块concurrent.futures.ThreadPoolExecutor(max_workers=N
使用 python grpc 服务器时, server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) 这是实例化 grpc 服务器
concurrent.futures.ThreadPoolExecutor 的文档说: Changed in version 3.5: If max_workers is None or not gi
在从 concurrent.futures 中决定将 max_workers 设置为什么时,需要考虑哪些因素? 只要您期望 Python 3.5+ 可用,是否有任何理由不将 max_workers 设
我是一名优秀的程序员,十分优秀!