benfred / py-spy

Sampling profiler for Python programs
MIT License
12.87k stars 431 forks source link

py-spy segfault with --subprocesses #724

Open singharpit94 opened 2 weeks ago

singharpit94 commented 2 weeks ago

Hi, I noticed that using py-spy with subprocesses ends up giving a segmentation fault error. Below is a minimal reproducer

from concurrent.futures import ProcessPoolExecutor

def lfilter(filt_b, filt_a, x_t, axis=-1):
    import scipy.signal
    y_t = scipy.signal.lfilter(filt_b, filt_a, x_t, axis=axis)
    return y_t

if __name__ == '__main__':
    for _ in range(100):
        with ProcessPoolExecutor(1) as executor:
            executor.submit(lfilter, [1.0], [1.0], [1.0]).result()

Used the below command to run py-spy

py-spy record -o <> --subprocesses -- <filepath>

Can you please suggest solution for the above issue.

singharpit94 commented 2 weeks ago

Might we related to https://github.com/benfred/py-spy/issues/638

benfred commented 2 weeks ago

What operating system, version of python and version of py-spy are you using here?

Fwiw, I just tried out your reproducer using ubuntu 22.04, python 3.12 and py-spy 0.4.0 and it worked fine for me

peytondmurray commented 2 weeks ago

I've been trying to reproduce this on Linux 6.6.59-1-lts x86_64 with the python 3.12.4 and the development version of py-spy as well, but haven't been able to. Are you on MacOS?

singharpit94 commented 2 weeks ago

I was using the 0.3.14 version but seems like using 0.4.0 does not gives the seg fault error.