[issue23510] multiprocessing bug SyncManager and 'with'

Davin Potts report at bugs.python.org
Tue Feb 24 18:20:55 CET 2015


Davin Potts added the comment:

A much simpler example of code triggering the described issue:

    import multiprocessing.managers
    with multiprocessing.managers.SyncManager() as s:
        print "here"


Running the above code in 2.7.9 results in an exception with the traceback:

    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
      File "/home/somewhere/python/lib/python2.7/multiprocessing/managers.py", line 602, in __exit__
        self.shutdown()
    AttributeError: 'SyncManager' object has no attribute 'shutdown'



This is because the implementation of context manager functionality for multiprocessing.managers.BaseManager appears to have a bug.  The above snippet of code might as well have been written to use BaseManager instead of SyncManager and the resulting behavior would have been the same.

To be fair, nothing in the documentation appears to suggest that BaseManager or its subclasses can / should be used with the 'with' statement (as proper context managers).  But it is also natural to react to the existence of '__enter__' and '__exit__' and think to try using it with a 'with' statement.

Specifically in BaseManager, it looks like self.shutdown should have been set via __enter__'s call to start() yet inside __exit__ it's not resolving.

I believe we need:
1) A patch to fix the broken behavior;
2) a test to validate that it works and specifically exercise the use of BaseManager with a 'with' statement;
3) an update to the docs to advertise context manager capability in these classes.

----------
stage:  -> needs patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23510>
_______________________________________


More information about the Python-bugs-list mailing list