python / cpython

The Python programming language
https://www.python.org/
Other
61.16k stars 29.52k forks source link

multiprocessing.Server swallows original exception traceback #78279

Open 4954efc8-616d-400d-b687-161d728199ce opened 6 years ago

4954efc8-616d-400d-b687-161d728199ce commented 6 years ago
BPO 34098
Nosy @pitrou, @gsalgado, @applio
PRs
  • python/cpython#8254
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['3.8', 'type-feature', 'library'] title = 'multiprocessing.Server swallows original exception traceback' updated_at = user = 'https://github.com/gsalgado' ``` bugs.python.org fields: ```python activity = actor = 'cheryl.sabella' assignee = 'none' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'salgado' dependencies = [] files = [] hgrepos = [] issue_num = 34098 keywords = ['patch'] message_count = 1.0 messages = ['321480'] nosy_count = 3.0 nosy_names = ['pitrou', 'salgado', 'davin'] pr_nums = ['8254'] priority = 'normal' resolution = None stage = 'patch review' status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue34098' versions = ['Python 3.8'] ```

    4954efc8-616d-400d-b687-161d728199ce commented 6 years ago

    multiprocessing.Server swallows original exception traceback, making it hard to debug. For example, the following code:

    from multiprocessing.managers import BaseManager
    
    class FooBar(object):
        def m(self):
            self._raise()
        def _raise(self):
            raise ValueError
    
    class MyManager(BaseManager):
        pass
    
    MyManager.register('Foo', callable=FooBar)
    manager = MyManager()
    manager.start()
    manager.Foo()._callmethod('m')
    manager.shutdown()

    Gives me the following exception:

    Traceback (most recent call last):
      File "/tmp/foo.py", line 15, in <module>
        manager.Foo()._callmethod('m')
      File "/usr/lib/python3.6/multiprocessing/managers.py", line 772, in _callmethod
        raise convert_to_error(kind, result)
    ValueError

    Ideally, I'd like to get something like this:

    multiprocessing.pool.RemoteTraceback: 
    """
    Traceback (most recent call last):
      File "/home/salgado/src/cpython/Lib/multiprocessing/managers.py", line 254, in serve_client
        res = function(*args, **kwds)
      File "/tmp/foo.py", line 5, in m
        self._raise()
      File "/tmp/foo.py", line 7, in _raise
        raise ValueError
    ValueError
    """
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/tmp/foo.py", line 15, in <module>
        manager.Foo()._callmethod('m')
      File "/home/salgado/src/cpython/Lib/multiprocessing/managers.py", line 811, in _callmethod
        raise convert_to_error(kind, result)
    ValueError
    zpz commented 1 month ago

    This is a simple but very annoying issue. I talked about it in my blog post here https://zpz.github.io/blog/python-mp-manager-2/#exceptions-in-the-server

    I'm thinking of creating a new issue with fixes.