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

python

#1

Hello,

I am trying to wrap python functions as it is recommended:
@newrelic.agent.background_task()
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))
pr.start()

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?


#2

@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.


#3

Thank you,

Should have initialized agent in each thread indeed.

def run(self):
_newrelic.agent.initialize(‘newrelic.ini’)
_newrelic.agent.register_application(timeout=10.0)
_your code here