Skip to content

Spans aren't exported when using multiprocessing with fork method #779

@alexmojaki

Description

@alexmojaki

With this code:

from multiprocessing import Process, set_start_method

import logfire

logfire.configure()


def worker():
    logfire.info('child')
    # logfire.force_flush()


if __name__ == '__main__':
    set_start_method('fork')
    with logfire.span('parent'):
        p = Process(target=worker)
        p.start()
        p.join()

the 'child' log appears in the console but not in the UI. It will appear in the UI if logfire.force_flush() is uncommented, or if fork is changed to spawn. If set_start_method isn't called then it depends on the OS. Side note, using fork also means that child will actually be a child span, as if context was propagated.

The issue here is that when using fork, atexit functions aren't called. This is supposedly fixed in 3.13 by python/cpython#114279 although I'm not seeing that on my machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions