import multiprocessing as mp import multiprocessing.managers as mmp import os, sys import psutil import traceback sout = sys.stdout def processes(): """ Print list of pid and child pids if any """ pid = os.getpid() pr = psutil.Process(pid) # First is always the current process pids = [pid] + pr.children() sout.write("Process IDs => " + str(pids) + "\n") # Create a base manager bm = mmp.BaseManager(('', 50000)) # Single process processes() # Now start the manager's subprocess bm.start() # Two processes - expected processes() # Shut it down bm.shutdown() # Back to single process processes() # Now create a syncmanager sm = mp.Manager() print type(sm) # Hmmm - two processes ? # SyncManager starts its own process without a call to start - this is undocumented processes() try: sout.write('Trying to start syncmanager ...\n') # This gets even more odd sm.start() except AssertionError as e: # raise # An assertion error is raised as apparently you can't start a SyncManager # without intializing it traceback.print_exc(file=sout) # So I can't start a SyncManager ? But documentation says nothing about it # I would expect I can do this as SyncManager is a subclass of BaseManager sout.write(str(issubclass(sm.__class__, bm.__class__)) + '\n') # So how to intialize the SyncManager ? # print dir(sm) # Documentation says nothing about an init # No methods above says anything about initializing a syncmanager. # O.K then - maybe I need to pass a address to it like BaseManager ? # That seems to work sm2 = mmp.SyncManager(('', 12345)) print type(sm) processes() # Try starting it ? sm2.start() # Expected - now there are 3, parent Python, hidden sm and known sm2 processes() # Shut sm2 down - good sm2.shutdown() # Not it is back to 2 - parent Python, hidden sm processes() # Can I shut sm down ? sm.shutdown() # Looks like that works # But that is odd as I didn't start it! processes() # Maybe then I can do this ? sm3 = mp.Manager(('', 12346)) # Looks like you cannot.