How does multiprocessing reference _default_context as if it were an attribute of the context submodule itself?

Hello all,

I’m having a hard time understanding this line in multiprocessing…

__all__ = [x for x in dir(context._default_context) if not x.startswith('_')]

At the point the line appears, context is a module object, but it doesn’t have an attribute _default_context. It does contain the class DefaultContext who’s __init__ method sets self._default_context, but that’s not an attribute of the module that contains the class?

multiprocessing/ doesn’t overwrite the name context by storing a context.DefaultContext object in it either, so I can’t quite work out what it’s referencing.

Any thoughts?

The context module does have a _default_context attribute: see line 326 for macOS, line 351 for Windows, and line 328 for all other platforms.

1 Like

Ah, that would be the reason for my confusion. Thanks!