4

在多处理环境中调用 RPy 函数是否安全?是否有任何关于 RPy 的多处理问题需要注意?

一个简单的例子可能如下:

from multiprocessing import Pool
from rpy import *

def f(x):
    return r.mean(x)


if __name__ == '__main__':
    p = Pool(5)
    print sum(p.map(f, [range(1, 1000000), range(2, 2000000), range(3, 3000000)]))
4

2 回答 2

1

Seeing that multiprocessing spawns new python instance for each worker instance in the pool and they share no common resources -- including instances of the R process, -- chances are it is thread-safe. Best way is to test it and see.

于 2011-04-18T21:02:54.773 回答
0

我使用多处理和 rpy2 没有问题。无法与 rpy (v1) 交谈,但它很有可能会起作用。

于 2011-05-06T15:08:26.840 回答