После вызова API, используя r из python, а затем используя многопоточность.
Код Python, вызывающий скрипт r:
from numpy import *
import scipy as sp
from pandas import *
from rpy2.robjects.packages import importr
import rpy2.robjects as ro
#import pandas.rpy.common as com
from rpy2.robjects import pandas2ri
pandas2ri.activate()
from rpy2.robjects.packages import importr
import rpy2.robjects as robjects
import time
from multiprocessing import Process
def long_r_function():
import rpy2.robjects as robjects
robjects.r("/home/e/Documents/Scripts.R") # pretend we have a long-running function in R
if __name__ == '__main__':
r_process = Process(target=long_r_function)
start_time = time.time()
r_process.start()
while r_process.is_alive():
print("R running...") # expect to be able to see this print from main process,
time.sleep(2) # while R does work in second process
print("Finished after ", time.time() - start_time, " seconds")
Как выполнить многопоточность процесса с использованием python после вызова кода r?