When using spawn, the child imports the main module. Keep worker definitions importable and put process or pool creation inside an if __name__ == "__main__" entry point.
Check the failure with a small fixture
A spawned child imports the main module and reaches process startup again before initialization finishes.
import multiprocessing as mp
def worker(sender):
sender.send("child completed")
sender.close()
def main():
context = mp.get_context("spawn")
receiver, sender = context.Pipe(duplex=False)
process = context.Process(target=worker, args=(sender,))
process.start()
sender.close()
process.join(timeout=10)
if process.is_alive():
process.terminate()
process.join()
raise RuntimeError("fixture child timed out")
assert process.exitcode == 0
assert receiver.poll(1)
assert receiver.recv() == "child completed"
receiver.close()
print("spawn entry point verified")
if __name__ == "__main__":
main()What the result means
Save the example as a .py file and execute that file; a notebook cell or standard-input session has different importability constraints. The worker is defined at module level so the spawned interpreter can locate it. Importing the module defines functions without immediately starting more child processes.
Choose the correction for your caller
Guard every path that creates a pool or process, including calls hidden inside startup helpers. Avoid starting work as an import side effect. Arguments and target functions must also satisfy the selected start method serialization rules; adding a guard cannot make a local lambda importable. The example explicitly chooses spawn so behavior does not depend on platform defaults, which differ across operating systems and Python versions.
Limits and the next check
Frozen executables may need freeze_support under the main guard according to their packaging contract. This fixture verifies one child and a bounded local pipe exchange; it does not validate a complete server worker lifecycle. Do not select fork merely to hide an import-safety problem, especially in a threaded application.
Related: Compare a related data or execution contract.
The embedded Python example was executed as an isolated local script on November 10, 2026 (KST), using Python 3.11.6. It demonstrates the stated boundary; it is not a test of your application or a promise of compatibility with every Python release.