New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TraitError while setting a python debbugger #1136

Closed
papachoco opened this Issue Mar 8, 2018 · 9 comments

Comments

Projects
None yet
2 participants
@papachoco

papachoco commented Mar 8, 2018

  • gevent version:1.3a2
  • Python version: Please be as specific as possible: "cPython 2.7.9 downloaded from python.org"
  • Operating System: macOS 10.13.3

Description:

While setting an ipython brake-point we get an exception.

The brake-point set is from IPython.terminal.debugger import set_trace;set_trace()

  from IPython.core.debugger import Tracer; Tracer()()
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/ipython-5.5.0-py2-none-any.ovo/IPython/core/debugger.py", line 167, in __init__
    self.debugger = Pdb(colors)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/ipython-5.5.0-py2-none-any.ovo/IPython/core/debugger.py", line 235, in __init__
    self.shell = TerminalInteractiveShell.instance()
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/traitlets-4.3.2-py2.py3-none-any.ovo/traitlets/config/configurable.py", line 412, in instance
    inst = cls(*args, **kwargs)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/ipython-5.5.0-py2-none-any.ovo/IPython/terminal/interactiveshell.py", line 438, in __init__
    super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/ipython-5.5.0-py2-none-any.ovo/IPython/core/interactiveshell.py", line 478, in __init__
    self.init_history()
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/ipython-5.5.0-py2-none-any.ovo/IPython/core/interactiveshell.py", line 1579, in init_history
    self.history_manager = HistoryManager(shell=self, parent=self)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/ipython-5.5.0-py2-none-any.ovo/IPython/core/history.py", line 544, in __init__
    self.save_flag = threading.Event()
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/traitlets-4.3.2-py2.py3-none-any.ovo/traitlets/traitlets.py", line 585, in __set__
    self.set(obj, value)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/traitlets-4.3.2-py2.py3-none-any.ovo/traitlets/traitlets.py", line 559, in set
    new_value = self._validate(obj, value)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/traitlets-4.3.2-py2.py3-none-any.ovo/traitlets/traitlets.py", line 591, in _validate
    value = self.validate(obj, value)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/traitlets-4.3.2-py2.py3-none-any.ovo/traitlets/traitlets.py", line 1677, in validate
    self.error(obj, value)
  File "/Users/cutz/Documents/NextThought/nti.dataserver-buildout/eggs/traitlets-4.3.2-py2.py3-none-any.ovo/traitlets/traitlets.py", line 1524, in error
    raise TraitError(e)
TraitError: The 'save_flag' trait of a HistoryManager instance must be a _Event or None, but a value of class 'gevent.event.Event' (i.e. <gevent.event.Event object at 0x1263362d0>) was specified.

The error does not occur with version 1.3a1

Carlos

@jamadden

This comment has been minimized.

Member

jamadden commented Mar 9, 2018

IPython has long had issue working with gevent (see other issues in this tracker). Does the standard pdb still work?

@jamadden

This comment has been minimized.

Member

jamadden commented Mar 9, 2018

To quote an email I sent another colleague:

I have largely given up on using IPython in gevent-patched programs lately; it's gotten very annoyingly strict about threads and things like that, and has been for some time. But these days I mostly interactively debug in Python 3, which uses IPython 6. I notice that Python 2 is stuck with IPython 5.5, and I don't remember it being so annoying. There has been a recent change with threading.Event and gevent that could affect this (Event is patched by default in 1.3a2). I will absolutely look into it, but if it's a case of IPython just being paranoid I'm not sure it will be worth reversing the change (the 'history' stuff is where I remember the most issues; perhaps that can be disabled).

@jamadden

This comment has been minimized.

Member

jamadden commented Mar 9, 2018

(Also, if you're still using Python 2.7.9 I would highly encourage you to update to Python 2.7.14.)

@papachoco

This comment has been minimized.

papachoco commented Mar 9, 2018

We are running in 2.7.14

@papachoco

This comment has been minimized.

papachoco commented Mar 9, 2018

regular pdb does work.

import pdb; pdb.set_trace()

@papachoco

This comment has been minimized.

papachoco commented Mar 9, 2018

The annoying thing about pdb is that any background greenlet that logs messages interrupts the debugging.

@jamadden

This comment has been minimized.

Member

jamadden commented Mar 9, 2018

We are running in 2.7.14

Ah. I guess that part of the bug template wasn't updated then.

@jamadden

This comment has been minimized.

Member

jamadden commented Mar 9, 2018

The code in question is digging into undocumented internals of the threading module:

    try:               # Event is a function returning an instance of _Event...
        save_flag = Instance(threading._Event, allow_none=True)
    except AttributeError:         # ...until Python 3.3, when it's a class.
        save_flag = Instance(threading.Event, allow_none=True)

gevent's monkey-patch currently only gets the public interface.

@jamadden

This comment has been minimized.

Member

jamadden commented Mar 9, 2018

I have a compatibility fix for this merged into master in #1137

Other than that, I can suggest two options:

  1. Modify your debugger invocation. If you currently insert something like this:
from IPython.terminal.debugger import set_trace; set_trace() ## DEBUG ##

Change that to

from gevent.event import Event; import threading; threading._Event = Event; from IPython.terminal.debugger import set_trace; set_trace() ## DEBUG ##
  1. Explicitly set Event=False in your call to monkey.patch_all(). That has a more global effect, though, so I would tend to recommend option 1.

@jamadden jamadden closed this in 24c9b94 Mar 9, 2018

jamadden added a commit that referenced this issue Mar 9, 2018

Merge pull request #1137 from gevent/issue1136
Also monkey-patch threading._Event on Python 2. Fixes #1136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment