def getFromThreadScope(target_thread, object_name): """Abuse optimizations in Jython or reflection in Java to get objects in other frames. For the ThreadStateMapping method, see Jython commit 8f00d52031 and http://bugs.jython.org/issue2321 For the Java reflection introspection, see https://web.archive.org/web/20150505022210/http://weblogs.java.net/blog/jjviana/archive/2010/06/09/dealing-glassfish-301-memory-leak-or-threadlocal-thread-pool-bad-ide https://web.archive.org/web/20150422074412/http://blog.igorminar.com/2009/03/identifying-threadlocal-memory-leaks-in.html """ try: # Jython 2.7 has a singleton-style dictionary that keeps track of the thread states. # Given a thread ID, it will return the ThreadState object from org.python.core import ThreadStateMapping frame = ThreadStateMapping._current_frames()[target_thread.getId()] except (ImportError, AttributeError): thread_state = getThreadState(target_thread) frame = thread_state.frame # The ThreadState object contains the current Python frame under execution. # Frames have all the needed context to execute, including the variable references in scope. return frame.f_locals[object_name]
"windows") if sys.version_info[0] == 2 and sys.version_info[1] < 5: IS_JYTH_LESS25 = True USE_CUSTOM_SYS_CURRENT_FRAMES = not hasattr(sys, '_current_frames') or IS_PYPY USE_CUSTOM_SYS_CURRENT_FRAMES_MAP = USE_CUSTOM_SYS_CURRENT_FRAMES and ( IS_PYPY or IS_IRONPYTHON) if USE_CUSTOM_SYS_CURRENT_FRAMES: # Some versions of Jython don't have it (but we can provide a replacement) if IS_JYTHON: from java.lang import NoSuchFieldException from org.python.core import ThreadStateMapping try: cachedThreadState = ThreadStateMapping.getDeclaredField( 'globalThreadStates') # Dev version except NoSuchFieldException: cachedThreadState = ThreadStateMapping.getDeclaredField( 'cachedThreadState') # Release Jython 2.7.0 cachedThreadState.accessible = True thread_states = cachedThreadState.get(ThreadStateMapping) def _current_frames(): as_array = thread_states.entrySet().toArray() ret = {} for thread_to_state in as_array: thread = thread_to_state.getKey() if thread is None: continue thread_state = thread_to_state.getValue() if thread_state is None:
# IFDEF CYTHON # pydev_log.debug("Using Cython speedups") # ELSE from _pydevd_bundle.pydevd_frame import PyDBFrame # ENDIF version = 11 if not hasattr(sys, '_current_frames'): # Some versions of Jython don't have it (but we can provide a replacement) if IS_JYTHON: from java.lang import NoSuchFieldException from org.python.core import ThreadStateMapping try: cachedThreadState = ThreadStateMapping.getDeclaredField('globalThreadStates') # Dev version except NoSuchFieldException: cachedThreadState = ThreadStateMapping.getDeclaredField('cachedThreadState') # Release Jython 2.7.0 cachedThreadState.accessible = True thread_states = cachedThreadState.get(ThreadStateMapping) def _current_frames(): as_array = thread_states.entrySet().toArray() ret = {} for thread_to_state in as_array: thread = thread_to_state.getKey() if thread is None: continue thread_state = thread_to_state.getValue() if thread_state is None: continue