Skip to content

Setting process group consumes I/O from debugger. #9

Closed

Description

@Michael-F-Ellis

First, thanks for writing remote_pdb! It works very well to set breaks in child processes in normal circumstances.

There seems to be a communication problem when the main python program is under control of a program such as entr or when the main program is launched from ipython and sets it's own process group.

Could you please take a look at the question I posted a couple of days ago on SO? It's rather long so I won't repost the contents here.

http://stackoverflow.com/questions/43823564/python-3-debug-child-process-running-under-control-of-entr

Thanks,
Mike Ellis

Activity

  1. ionelmc commented on May 8, 2017

    @ionelmc
    Owner

    I cannot produce the problem on Ubuntu but I suspect it's a lingering socket issue - this happens only after a restart right?

  2. ionelmc commented on May 8, 2017

    @ionelmc
    Owner

    I do set SO_REUSEADDR in https://github.com/ionelmc/python-remote-pdb/blob/master/src/remote_pdb.py#L69 - perhaps you could patch it up locally to additionally set SO_REUSEPORT and report results? I don't have an OSX system to play with.

  3. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    Thanks for the quick responses. The only pure Linux system I've got handy is a Raspberry Pi running Raspbian Jessie. I'll try it out on that to see if the problem occurs there and let you know the result. Then I'll try patching in SO_REUSEPORT and running it on OS X. More later ...

  4. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    I've confirmed the problem is not occurring in Linux.

  5. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    I added

            listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, True)
    

    at line 70.

    No effect on the problem (on OS X). Just to clarify, the connection has always succeeded. I see

    CRITICAL:root:RemotePdb accepted connection from ('127.0.0.1', 60462).
    RemotePdb accepted connection from ('127.0.0.1', 60462).
    

    with or without SO_REUSEPORT. The problem is that I don't get a Pdb prompt and nothing I type produces a response.

  6. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    I've been able to confirm the following on OS X

    1. When the problem occurs, the code never makes it past the the call to Pdb__iniit__ .
    2. When I run my test file bare at the command line (python mp.py) the problem doesn't occur and the code makes it past Pdb.init and all the way to the end of RemotePdb.init
  7. ionelmc commented on May 8, 2017

    @ionelmc
    Owner

    One way to figure this one out: install hunter and just add import hunter; hunter.trace() somewhere convenient - perhaps in the child function?

  8. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    I'll definitely give that a try! I was looking earlier today for a tracing program to help a fellow engineer explore some unfamiliar Python code. This looks perfect. I think I'll need to trace into Pdb itself since that's where things seem to be going wrong.

  9. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    Pdb seems to be going down the rabbit hole trying to import readline.

    [...]llis/anaconda3/lib/python3.5/pdb.py:139   call          def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
    [...]llis/anaconda3/lib/python3.5/pdb.py:141   line              bdb.Bdb.__init__(self, skip=skip)
    [...]llis/anaconda3/lib/python3.5/pdb.py:142   line              cmd.Cmd.__init__(self, completekey, stdin, stdout)
    [...]llis/anaconda3/lib/python3.5/pdb.py:143   line              if stdout:
    [...]llis/anaconda3/lib/python3.5/pdb.py:144   line                  self.use_rawinput = 0
    [...]llis/anaconda3/lib/python3.5/pdb.py:145   line              self.prompt = '(Pdb) '
    [...]llis/anaconda3/lib/python3.5/pdb.py:146   line              self.aliases = {}
    [...]llis/anaconda3/lib/python3.5/pdb.py:147   line              self.displaying = {}
    [...]llis/anaconda3/lib/python3.5/pdb.py:148   line              self.mainpyfile = ''
    [...]llis/anaconda3/lib/python3.5/pdb.py:149   line              self._wait_for_mainpyfile = False
    [...]llis/anaconda3/lib/python3.5/pdb.py:150   line              self.tb_lineno = {}
    [...]llis/anaconda3/lib/python3.5/pdb.py:152   line              try:
    [...]llis/anaconda3/lib/python3.5/pdb.py:153   line                  import readline
    

    More later. Have to eat dinner now. Hunter seems downright awesome!

  10. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    It's hanging during the import readline. I tried setting hunter to trace readline but that's a .so, so of course no luck ...

  11. Michael-F-Ellis commented on May 8, 2017

    @Michael-F-Ellis
    Author

    Solved! It's an old OS X python issue that has either crept back in or was never fixed in Pdb. The fix is to set up to ignore SIGTTOU before importing readline. See http://bugs.python.org/issue14892 for details.

    I cured the problem by patching my local copy of pdb.Pdb as shown below.

    class Pdb(bdb.Bdb, cmd.Cmd):
    
        _previous_sigint_handler = None
    
        def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
                     nosigint=False):
            bdb.Bdb.__init__(self, skip=skip)
            cmd.Cmd.__init__(self, completekey, stdin, stdout)
            if stdout:
                self.use_rawinput = 0
            self.prompt = '(Pdb) '
            self.aliases = {}
            self.displaying = {}
            self.mainpyfile = ''
            self._wait_for_mainpyfile = False
            self.tb_lineno = {}
            # Try to load readline if it exists
            try:
    ############ FIX OSX BUG ######################################
                import sys
                if sys.platform == 'darwin':
                    import signal
                    signal.signal(signal.SIGTTOU, signal.SIG_IGN)
    ############ END FIX ##########################################
                import readline
                # remove some common file name delimiters
                readline.set_completer_delims(' \t\n`@#$%^&*()=+[{]}\\|;:\'",<>?')
            except ImportError:
                pass               
    

    Thanks much for your generous help and for hunter.

    Cheers,
    Mike

  12. ionelmc commented on May 8, 2017

    @ionelmc
    Owner

    Nice find! I'll add this to the readme at the very least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions