多处理 Python 类对象
假设我有一个 Python 类:
class Something:
def __init__(self, a, b, c):
initialize_object_with_args()
def run(self):
do_something()
def result(self):
return result
现在我想创建该类的多个对象(所有这些对象都是独立的 - 不需要对象之间的数据交换)并在具有多核 CPU 的单台 PC 上并行运行它们。 ..唯一改变的是每次运行的输入参数(a,b,c)...
所以我需要这个:
results = []
[PARALLEL START]
obj = Something(a, b, c)
obj.run()
results.append(obj.results())
[PARALLEL END]
然后我可以评估结果!我看到多处理模块就是我所需要的,但我不知道具体细节,也不知道它是否可以做我需要的事情,也不知道如何做?
快速编辑:我需要能够使用 Python 来完成此操作...没有外部模块...只需标准 Python 安装...
So I let's say I have a Python class:
class Something:
def __init__(self, a, b, c):
initialize_object_with_args()
def run(self):
do_something()
def result(self):
return result
Now I want to create multiple objects of that class (all of which are independent - no need for data exchange between the objects) and run them in parallel on a single PC with a multicore CPU...the only thing changing are the input arguments (a,b, c) for each run...
So I would need this:
results = []
[PARALLEL START]
obj = Something(a, b, c)
obj.run()
results.append(obj.results())
[PARALLEL END]
I could then evaluate the results! I see that the multiprocessing module would be what I need but i don't know the specifics nor if it can do what I need nor how?
Quick Edit: I need to be able to do this with Python...no external modules...just the standard Python install...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它似乎与这个非常相似
It seems to be very similar to this
看一下 http://wiki.python.org/moin/ParallelProcessing ,尤其是 < a href="http://pypi.python.org/pypi/pprocess" rel="nofollow">http://pypi.python.org/pypi/pprocess 。
这个小库可以完全满足您的需求: http://honeypot.net/yet-another-python -地图
Take a look at http://wiki.python.org/moin/ParallelProcessing , especially the http://pypi.python.org/pypi/pprocess .
This small library could do exactly what you want: http://honeypot.net/yet-another-python-map