Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions stdlib/multiprocessing/context.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ if sys.platform != "win32":
Process: ClassVar[type[ForkServerProcess]]

def _force_start_method(method: str) -> None: ...
def get_spawning_popen() -> Any | None: ...
def set_spawning_popen(popen: Any) -> None: ...

if sys.platform != "win32":
def get_spawning_popen() -> popen_forkserver.Popen | popen_spawn_posix.Popen | None: ...
Copy link
Contributor Author

@donBarbos donBarbos Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I use popen_fork.Popen | None here? (popen_fork.Popen is parent of popen_forkserver.Popen and popen_spawn_posix.Popen)
And should I use Protocol for return type "_DupFd" below, instead of popen_forkserver._DupFd | popen_spawn_posix._DupFd | resource_sharer.DupFd?

def set_spawning_popen(popen: popen_forkserver.Popen | popen_spawn_posix.Popen | None) -> None: ...

else:
def get_spawning_popen() -> popen_spawn_win32.Popen | None: ...
def set_spawning_popen(popen: popen_spawn_win32.Popen | None) -> None: ...

def assert_spawning(obj: Any) -> None: ...
9 changes: 7 additions & 2 deletions stdlib/multiprocessing/heap.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from _typeshed import Incomplete
from collections.abc import Callable
from mmap import mmap
from multiprocessing import popen_forkserver, popen_spawn_posix, resource_sharer
from typing import Protocol, type_check_only
from typing_extensions import TypeAlias

Expand All @@ -24,7 +24,12 @@ if sys.platform != "win32":
class _SupportsDetach(Protocol):
def detach(self) -> int: ...

def reduce_arena(a: Arena) -> tuple[Callable[[int, _SupportsDetach], Arena], tuple[int, Incomplete]]: ...
def reduce_arena(
a: Arena,
) -> tuple[
Callable[[int, _SupportsDetach], Arena],
tuple[int, popen_forkserver._DupFd | popen_spawn_posix._DupFd | resource_sharer.DupFd],
]: ...
def rebuild_arena(size: int, dupfd: _SupportsDetach) -> Arena: ...

class Heap:
Expand Down
4 changes: 2 additions & 2 deletions stdlib/multiprocessing/reduction.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from abc import ABCMeta
from builtins import type as Type # alias to avoid name clash
from collections.abc import Callable
from copyreg import _DispatchTableType
from multiprocessing import connection
from multiprocessing import connection, popen_forkserver, popen_spawn_posix, resource_sharer
from socket import socket
from typing import Any, Final

Expand Down Expand Up @@ -50,7 +50,7 @@ else:
def send_handle(conn: HasFileno, handle: int, destination_pid: Unused) -> None: ...
def recv_handle(conn: HasFileno) -> int: ...
def sendfds(sock: socket, fds: list[int]) -> None: ...
def DupFd(fd: int) -> Any: ... # Return type is really hard to get right
def DupFd(fd: int) -> popen_forkserver._DupFd | popen_spawn_posix._DupFd | resource_sharer.DupFd: ...

# These aliases are to work around pyright complaints.
# Pyright doesn't like it when a class object is defined as an alias
Expand Down