Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Problem with python multiprocessing




I am trying to wrap python functions as it is recommended:
def func(x):

And it works. But when I try to pass it to the multiprocessing module:

from multiprocessing import Process
pr = Process(target=func, args=(x))

It stops counting this func() as transactions. It still shows CPU usage but not correctly.
Is there a way to monitor func() in this situation?


@aleksandr.nemchanino I believe the problem you are having is that you are trying to collect data in a process different to where the agent was registered/initialized. When using multiprocessing you’ll want to make sure you are initializing and registering the agent in the process where you are using the background_task api, not initializing and registering the agent in the parent process. Due to the way multiprocessing terminates the subprocess, you’ll also want to be sure to call shutdown_agent.


Thank you,

Should have initialized agent in each thread indeed.

def run(self):
_your code here