Beispiel #1
0
def test_interrupt_main_thread():

    from _pydevd_bundle.pydevd_constants import IS_PY39_OR_GREATER

    class MyThread(threading.Thread):
        def __init__(self, interrupt_thread_callback):
            threading.Thread.__init__(self)
            self.interrupt_thread_callback = interrupt_thread_callback

        def run(self):
            time.sleep(.5)
            self.interrupt_thread_callback()

    initial_time = time.time()
    interrupt_only_on_callback = IS_PYPY or IS_PY39_OR_GREATER
    if interrupt_only_on_callback:
        timeout = 2
    else:
        timeout = 20
    try:
        t = MyThread(create_interrupt_this_thread_callback())
        t.start()
        time.sleep(timeout)
    except KeyboardInterrupt:
        if not interrupt_only_on_callback:
            assert time.time() - initial_time < timeout
    else:
        raise AssertionError('Expected main thread to be interrupted.')
Beispiel #2
0
 def run(self):
     try:
         self.interrupt_thread = create_interrupt_this_thread_callback()
         while True:
             time.sleep(.2)
     except KeyboardInterrupt:
         self.interrupted = True
     finally:
         self.finished = True
Beispiel #3
0
def _run_with_interrupt_thread(original_func, py_db, curr_thread, frame, expression, is_exec):
    on_interrupt_threads = None
    timeout_tracker = py_db.timeout_tracker  # : :type timeout_tracker: TimeoutTracker

    interrupt_thread_timeout = pydevd_constants.PYDEVD_INTERRUPT_THREAD_TIMEOUT

    if interrupt_thread_timeout > 0:
        on_interrupt_threads = pydevd_timeout.create_interrupt_this_thread_callback()
        pydev_log.info('Doing evaluate with interrupt threads timeout: %s.', interrupt_thread_timeout)

    if on_interrupt_threads is None:
        return original_func(py_db, frame, expression, is_exec)
    else:
        with timeout_tracker.call_on_timeout(interrupt_thread_timeout, on_interrupt_threads):
            return original_func(py_db, frame, expression, is_exec)
Beispiel #4
0
def test_timeout_0_time():
    class _DummyPyDb(object):
        def __init__(self):
            self.created_pydb_daemon_threads = {}

    raise_timeout = pydevd_timeout.create_interrupt_this_thread_callback()

    def on_timeout(arg):
        assert arg == 1
        raise_timeout()

    py_db = _DummyPyDb()
    timeout_tracker = pydevd_timeout.TimeoutTracker(py_db)
    try:
        with timeout_tracker.call_on_timeout(0, on_timeout, kwargs={'arg': 1}):
            time.sleep(1)
    except KeyboardInterrupt:
        pass
def test_interrupt_main_thread():
    class MyThread(threading.Thread):
        def __init__(self, interrupt_thread_callback):
            threading.Thread.__init__(self)
            self.interrupt_thread_callback = interrupt_thread_callback

        def run(self):
            time.sleep(.5)
            self.interrupt_thread_callback()

    initial_time = time.time()
    if IS_PYPY:
        timeout = 2
    else:
        timeout = 20
    try:
        t = MyThread(create_interrupt_this_thread_callback())
        t.start()
        time.sleep(timeout)
    except KeyboardInterrupt:
        if not IS_PYPY:
            assert time.time() - initial_time < timeout
    else:
        raise AssertionError('Expected main thread to be interrupted.')