Hi,
I'm using python 2.6 in windows 7 x64 with rpy 1.5.1 and R 2.9.1 and what
I'm trying to do is run R.arima models (and predictions) using python's
multiprocessing pool.map function and I keep getting the following error:
Traceback (most recent call last):
  File "c:\Python26\lib\multiprocessing\process.py", line 231, in _bootstrap
    self.run()
  File "c:\Python26\lib\multiprocessing\process.py", line 88, in run
    self._target(*self._args, **self._kwargs)
  File "c:\Python26\lib\multiprocessing\pool.py", line 71, in worker
    put((job, i, result))
PicklingError: Can't pickle <class 'rpy.RPy_RException'>: attribute lookup
rpy.RPy_RException failed

Below is a snippet of my code:

import time
import multiprocessing

from rpy import *

def _pickle_method(method):
    func_name = method.im_func.__name__
    obj = method.im_self
    cls = method.im_class
    return _unpickle_method,(func_name,obj,cls)
def _unpickle_method(func_name,obj,cls):
    for cls in cls.mro():
        try:
            func = cls.__dict__[func_name]
        except KeyError:
            pass
        else:
            break
    return func.__get__(obj,cls)

import copy_reg
import types

copy_reg.pickle(types.MethodType, _pickle_method, _unpickle_method)

def testLoop(args):
  loop_test = args[0]
  raw_datas = args[1]
  rows = args[2]
  set_default_mode(NO_CONVERSION)
  ts = r.ts(raw_datas,frequency=rows)
  tmp =
r.arima(ts,order=r.c(loop_test[0],loop_test[1],loop_test[2]),seasonal=r.list(order=r.c(loop_test[3],loop_test[4],loop_test[5])))
  set_default_mode(BASIC_CONVERSION)
  s = r.predict(tmp,rows)
  return s

def functionTesterMain(pool,num_processes,raw_datas,rows):
  loops = [[1, 0, 1, 0, 0, 0], [1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 2, 0], [1,
1, 1, 0, 0, 0], [1, 1, 1, 0, 1, 0], [1, 1, 1, 0, 2, 0], [1, 2, 1, 0, 0, 0],
[1, 2, 1, 0, 1, 0],[1, 2, 1, 0, 2, 0],[1, 0, 1, 0, 0, 1],[1, 0, 1, 0, 0, 3],
[1, 0, 1, 0, 1, 3], [1, 0, 1, 0, 2, 3]]
  num_args = []
  for n in loops:
    p = [n,raw_datas,rows]
    num_args.append(p)
  rss = pool.map(testLoop,num_args)
  return rss

if __name__ == '__main__':
  num_processes = multiprocessing.cpu_count()
  pool = multiprocessing.Pool(num_processes)
  for i in range(1,4):
    j = [i]*20
    a = functionTesterMain(pool,num_processes,j,10)
    print "-----------"
    print "a " + str(a)

I've added the copy_reg functions to help with pickling unbounded functions
but I dont think that is causing the errors here. Can anyone help me with
it? I'm trying to use new versions of R and RPy but the windows binaries for
them don't seem to work with python 2.6 so i've settled with the ones that
work with it.
Thanks again for any help
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to