Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using profilehooks with classes derived from multiprocessing.Process #4

Open
lebedov opened this issue Jan 2, 2015 · 2 comments
Open

Comments

@lebedov
Copy link

lebedov commented Jan 2, 2015

Is there some way to use profilehooks to profile the body of a class derived from multiprocessing.Process? The following code doesn't seem to report any function calls:

import multiprocessing as mp
from profilehooks import profile
import numpy as np

class MyProcess(mp.Process):
    def __init__(self, x): 
        super(MyProcess, self).__init__()
        self.x = x 

    @profile
    def run(self):
        return np.linalg.pinv(self.x)

if __name__ == '__main__':
    p = MyProcess(np.random.rand(100, 100))
    p.start()

(One can obviously profile the contents of the run() method using profile/cProfile directly, but I'm curious whether the the convenience of profilehooks can be exploited in the above situation.)

@mgedmin
Copy link
Owner

mgedmin commented Jan 5, 2015

The simplest way would probably be to use @profile(immediate=True). I tested it with your code example; it seems to work fine.

I admit that I don't quite understand how multiprocessing works. It doesn't seem to be executing any top-level module code, or run any atexit hooks (even when registered in the child process).

It would be good to add a note about this to the documentation. I'll keep this issue open until that's done.

@lebedov
Copy link
Author

lebedov commented Jan 5, 2015

Thanks - confirming that your suggestion works with Python 2.7.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants