Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class _ThreadInfo(object):
next_thread_id = partial(next, itertools.count())
def __init__(self):
self.state = STATE_RUN
self.thread_id = self.next_thread_id()
class _CustomSingleNotificationBehavior(AbstractSingleNotificationBehavior):
NOTIFY_OF_PAUSE_TIMEOUT = .01
__slots__ = AbstractSingleNotificationBehavior.__slots__ + ['notification_queue']
def __init__(self, py_db):
try:
from queue import Queue
except ImportError:
from Queue import Queue
super(_CustomSingleNotificationBehavior, self).__init__(py_db)
self.notification_queue = Queue()
@overrides(AbstractSingleNotificationBehavior.send_resume_notification)
def send_resume_notification(self, *args, **kwargs):
# print('put resume', threading.current_thread())
self.notification_queue.put('resume')
@overrides(AbstractSingleNotificationBehavior.send_suspend_notification)
def send_suspend_notification(self, *args, **kwargs):
from _pydev_bundle.pydev_override import overrides
STATE_RUN = 1
STATE_SUSPEND = 2
class _ThreadInfo(object):
next_thread_id = partial(next, itertools.count())
def __init__(self):
self.state = STATE_RUN
self.thread_id = self.next_thread_id()
class _CustomSingleNotificationBehavior(AbstractSingleNotificationBehavior):
NOTIFY_OF_PAUSE_TIMEOUT = .01
__slots__ = AbstractSingleNotificationBehavior.__slots__ + ['notification_queue']
def __init__(self, py_db):
try:
from queue import Queue
except ImportError:
from Queue import Queue
super(_CustomSingleNotificationBehavior, self).__init__(py_db)
self.notification_queue = Queue()
@overrides(AbstractSingleNotificationBehavior.send_resume_notification)
def send_resume_notification(self, *args, **kwargs):
# print('put resume', threading.current_thread())
def __init__(self, py_db):
AbstractSingleNotificationBehavior.__init__(self)
# If True, pydevd will send a single notification when all threads are suspended/resumed.
self.multi_threads_single_notification = False
self._py_db = weakref.ref(py_db)
self._callbacks_lock = threading.Lock()
self._callbacks = []
self._last_suspend_notification_time = self._suspend_time_request
self.send_suspend_notification(thread_id, stop_reason)
try:
yield # At this point the thread must be actually suspended.
finally:
# on resume (step, continue all):
with self._lock:
self._suspended_thread_ids.remove(thread_id)
if self._last_resume_notification_time < self._last_suspend_notification_time:
self._last_resume_notification_time = self._last_suspend_notification_time
self.send_resume_notification(thread_id)
class ThreadsSuspendedSingleNotification(AbstractSingleNotificationBehavior):
__slots__ = AbstractSingleNotificationBehavior.__slots__ + [
'multi_threads_single_notification', '_py_db', '_callbacks', '_callbacks_lock']
def __init__(self, py_db):
AbstractSingleNotificationBehavior.__init__(self)
# If True, pydevd will send a single notification when all threads are suspended/resumed.
self.multi_threads_single_notification = False
self._py_db = weakref.ref(py_db)
self._callbacks_lock = threading.Lock()
self._callbacks = []
def add_on_resumed_callback(self, callback):
with self._callbacks_lock:
self._callbacks.append(callback)
@overrides(AbstractSingleNotificationBehavior.send_resume_notification)
def send_resume_notification(self, thread_id):
@overrides(AbstractSingleNotificationBehavior.send_suspend_notification)
def send_suspend_notification(self, thread_id, stop_reason):
py_db = self._py_db()
if py_db is not None:
py_db.writer.add_command(py_db.cmd_factory.make_thread_suspend_single_notification(py_db, thread_id, stop_reason))
if stop_reason != CMD_THREAD_SUSPEND or pause_requested:
if self._suspend_time_request > self._last_suspend_notification_time:
self._last_suspend_notification_time = self._suspend_time_request
self.send_suspend_notification(thread_id, stop_reason)
try:
yield # At this point the thread must be actually suspended.
finally:
# on resume (step, continue all):
with self._lock:
self._suspended_thread_ids.remove(thread_id)
if self._last_resume_notification_time < self._last_suspend_notification_time:
self._last_resume_notification_time = self._last_suspend_notification_time
self.send_resume_notification(thread_id)
class ThreadsSuspendedSingleNotification(AbstractSingleNotificationBehavior):
__slots__ = AbstractSingleNotificationBehavior.__slots__ + [
'multi_threads_single_notification', '_py_db', '_callbacks', '_callbacks_lock']
def __init__(self, py_db):
AbstractSingleNotificationBehavior.__init__(self)
# If True, pydevd will send a single notification when all threads are suspended/resumed.
self.multi_threads_single_notification = False
self._py_db = weakref.ref(py_db)
self._callbacks_lock = threading.Lock()
self._callbacks = []
def add_on_resumed_callback(self, callback):
with self._callbacks_lock:
self._callbacks.append(callback)
@overrides(AbstractSingleNotificationBehavior.send_resume_notification)
def send_resume_notification(self, thread_id):
py_db = self._py_db()
if py_db is not None:
py_db.writer.add_command(py_db.cmd_factory.make_thread_resume_single_notification(thread_id))
with self._callbacks_lock:
callbacks = self._callbacks
self._callbacks = []
for callback in callbacks:
callback()
def notify_thread_suspended(self, thread_id, stop_reason):
if self.multi_threads_single_notification:
with AbstractSingleNotificationBehavior.notify_thread_suspended(self, thread_id, stop_reason):
yield
else:
yield