gaogaotiantian / viztracer

VizTracer is a low-overhead logging/debugging/profiling tool that can trace and visualize your python code execution.
https://viztracer.readthedocs.io/
Apache License 2.0
5.21k stars 385 forks source link

AttributeError: Can't get attribute 'Bar' on <module '__main__' from 'miniconda3/envs/3.12.0/bin/viztracer'> #422

Closed Honesty-of-the-Cavernous-Tissue closed 7 months ago

Honesty-of-the-Cavernous-Tissue commented 7 months ago

python: 3.12.0 viztracer: 0.16.2 os: macOS

here's my test script

from multiprocessing import get_context

class Bar:
    def __init__(self):
        self.total = 0
        ...

    def __add__(self, other):
        counter = Bar()
        for attr, val in counter.__dict__.items():
            if isinstance(val, int):
                counter[attr] += self[attr] + other[attr]
        return counter

    def __getitem__(self, item):
        return self.__getattribute__(item)

    def __setitem__(self, key, value):
        self.__setattr__(key, value)

def foo(frag):
    counter = Bar()
    counter.total += frag
    return counter

if __name__ == '__main__':
    frags = [*range(8)]
    with get_context('spawn').Pool(8) as pool:
        _ = sum(pool.imap_unordered(foo, frags), start=Bar())

after ran viztracer test.py got this error image