def request_terminate_process(self, py_db): # We mark with a terminate_requested to avoid that paused threads start running # (we should terminate as is without letting any paused thread run). py_db.terminate_requested = True run_as_pydevd_daemon_thread(py_db, self._terminate_if_commands_processed, py_db)
def test_single_notification_1(single_notification_behavior, notification_queue): ''' 1. Resume before pausing 2nd thread - user pauses all (2) threads - break first -> send notification - user presses continue all before second is paused - 2nd should not pause nor send notification - resume all notification should be sent ''' thread_info1 = _ThreadInfo() thread_info2 = _ThreadInfo() # pause all = set_suspend both single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND t = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) thread_info1.state = STATE_RUN # Set 2 to run before it starts (should not send additional message). thread_info2.state = STATE_RUN t.join() assert notification_queue.qsize() == 2 assert notification_queue.get() == 'suspend' assert notification_queue.get() == 'resume' assert notification_queue.qsize() == 0 # Run thread 2 only now (no additional notification). t = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) t.join() assert notification_queue.qsize() == 0
def test_single_notification_2(single_notification_behavior, notification_queue): ''' 2. Pausing all then stepping - user pauses all (2) threads - break first -> send notification - break second (no notification) - user steps in second - suspend in second -> send resume/pause notification on step ''' thread_info1 = _ThreadInfo() thread_info2 = _ThreadInfo() dummy_py_db = _DummyPyDB() # pause all = set_suspend both single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND # Leave both in break mode t1 = run_as_pydevd_daemon_thread( dummy_py_db, single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) wait_for_notification(notification_queue, 'suspend') t2 = run_as_pydevd_daemon_thread( dummy_py_db, single_notification_behavior.do_wait_suspend, thread_info2, CMD_THREAD_SUSPEND) # Step would actually be set state to STEP, which would result in resuming # and then stopping again as if it was a SUSPEND (which calls a set_supend again with # the step mode). thread_info2.state = STATE_RUN join_thread(t2) wait_for_notification(notification_queue, 'resume') single_notification_behavior.increment_suspend_time() thread_info2.state = STATE_SUSPEND t2 = run_as_pydevd_daemon_thread( dummy_py_db, single_notification_behavior.do_wait_suspend, thread_info2, CMD_STEP_OVER) wait_for_notification(notification_queue, 'suspend') thread_info1.state = STATE_RUN thread_info2.state = STATE_RUN # First does a resume notification, the other remains quiet. wait_for_notification(notification_queue, 'resume') join_thread(t2) join_thread(t1) assert notification_queue.qsize() == 0
def test_single_notification_4(single_notification_behavior, notification_queue, _dummy_pydb): ''' 4. Delayed stop - user presses pause - stops first (2nd keeps running) - user steps on first - 2nd hits before first ends step (should not send any notification) - when step finishes send notification ''' thread_info1 = _ThreadInfo() thread_info2 = _ThreadInfo() single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND t1 = run_as_pydevd_daemon_thread( _dummy_pydb, single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) wait_for_notification(notification_queue, 'suspend') thread_info1.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t1) t2 = run_as_pydevd_daemon_thread( _dummy_pydb, single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) time.sleep(.1) assert notification_queue.qsize() == 0 single_notification_behavior.increment_suspend_time() thread_info1.state = STATE_SUSPEND t1 = run_as_pydevd_daemon_thread( _dummy_pydb, single_notification_behavior.do_wait_suspend, thread_info1, CMD_STEP_OVER) wait_for_notification(notification_queue, 'suspend') thread_info2.state = STATE_RUN thread_info1.state = STATE_RUN join_thread(t1) join_thread(t2) wait_for_notification(notification_queue, 'resume') assert notification_queue.qsize() == 0
def test_single_notification_2(single_notification_behavior, notification_queue): ''' 2. Pausing all then stepping - user pauses all (2) threads - break first -> send notification - break second (no notification) - user steps in second - suspend in second -> send resume/pause notification on step ''' thread_info1 = _ThreadInfo() thread_info2 = _ThreadInfo() # pause all = set_suspend both single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND # Leave both in break mode t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) wait_for_notification(notification_queue, 'suspend') t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info2, CMD_THREAD_SUSPEND) # Step would actually be set state to STEP, which would result in resuming # and then stopping again as if it was a SUSPEND (which calls a set_supend again with # the step mode). thread_info2.state = STATE_RUN join_thread(t2) wait_for_notification(notification_queue, 'resume') single_notification_behavior.increment_suspend_time() thread_info2.state = STATE_SUSPEND t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info2, CMD_STEP_OVER) wait_for_notification(notification_queue, 'suspend') thread_info1.state = STATE_RUN thread_info2.state = STATE_RUN # First does a resume notification, the other remains quiet. wait_for_notification(notification_queue, 'resume') join_thread(t2) join_thread(t1) assert notification_queue.qsize() == 0
def test_single_notification_1(single_notification_behavior, notification_queue): ''' 1. Resume before pausing 2nd thread - user pauses all (2) threads - break first -> send notification - user presses continue all before second is paused - 2nd should not pause nor send notification - resume all notification should be sent ''' thread_info1 = _ThreadInfo() thread_info2 = _ThreadInfo() # pause all = set_suspend both single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND dummy_py_db = _DummyPyDB() t = run_as_pydevd_daemon_thread( dummy_py_db, single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) thread_info1.state = STATE_RUN # Set 2 to run before it starts (should not send additional message). thread_info2.state = STATE_RUN t.join() assert notification_queue.qsize() == 2 assert notification_queue.get() == 'suspend' assert notification_queue.get() == 'resume' assert notification_queue.qsize() == 0 # Run thread 2 only now (no additional notification). t = run_as_pydevd_daemon_thread( dummy_py_db, single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) t.join() assert notification_queue.qsize() == 0
def test_single_notification_4(single_notification_behavior, notification_queue): ''' 4. Delayed stop - user presses pause - stops first (2nd keeps running) - user steps on first - 2nd hits before first ends step (should not send any notification) - when step finishes send notification ''' thread_info1 = _ThreadInfo() thread_info2 = _ThreadInfo() single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) wait_for_notification(notification_queue, 'suspend') thread_info1.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t1) t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) time.sleep(.1) assert notification_queue.qsize() == 0 single_notification_behavior.increment_suspend_time() thread_info1.state = STATE_SUSPEND t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_STEP_OVER) wait_for_notification(notification_queue, 'suspend') thread_info2.state = STATE_RUN thread_info1.state = STATE_RUN join_thread(t1) join_thread(t2) wait_for_notification(notification_queue, 'resume') assert notification_queue.qsize() == 0
def test_single_notification_3(single_notification_behavior, notification_queue, _dummy_pydb): ''' 3. Deadlocked thread - user adds breakpoint in thread.join() -- just before threads becomes deadlocked - breakpoint hits -> send notification - pauses 2nd thread (no notification) - user steps over thead.join() -> never completes - user presses pause - second thread is already stopped - send notification regarding 2nd thread (still stopped). - leave both threads running: no suspend should be shown as there are no stopped threads - when thread is paused, show suspend notification ''' # i.e.: stopping at breakpoint thread_info1 = _ThreadInfo() single_notification_behavior.increment_suspend_time() thread_info1.state = STATE_SUSPEND t1 = run_as_pydevd_daemon_thread( _dummy_pydb, single_notification_behavior.do_wait_suspend, thread_info1, CMD_SET_BREAK) # i.e.: stop because of breakpoint thread_info2 = _ThreadInfo() thread_info2.state = STATE_SUSPEND t2 = run_as_pydevd_daemon_thread( _dummy_pydb, single_notification_behavior.do_wait_suspend, thread_info2, CMD_SET_BREAK) wait_for_notification(notification_queue, 'suspend') # i.e.: step over (thread 2 is still suspended and this one never completes) thread_info1.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t1) # On pause we should notify that the thread 2 is suspended (after timeout if no other thread suspends first). single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND wait_for_notification(notification_queue, 'suspend') thread_info2.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t2) assert notification_queue.qsize() == 0 assert not single_notification_behavior._suspended_thread_ids # Now, no threads are running and pause is pressed # (maybe we could do a thread dump in this case as this # means nothing is stopped after pause is requested and # the timeout elapses). single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND time.sleep(single_notification_behavior.NOTIFY_OF_PAUSE_TIMEOUT * 2) assert notification_queue.qsize() == 0 t1 = run_as_pydevd_daemon_thread( _dummy_pydb, single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) wait_for_notification(notification_queue, 'suspend') thread_info1.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t1) assert notification_queue.qsize() == 0
def test_single_notification_3(single_notification_behavior, notification_queue): ''' 3. Deadlocked thread - user adds breakpoint in thread.join() -- just before threads becomes deadlocked - breakpoint hits -> send notification - pauses 2nd thread (no notification) - user steps over thead.join() -> never completes - user presses pause - second thread is already stopped - send notification regarding 2nd thread (still stopped). - leave both threads running: no suspend should be shown as there are no stopped threads - when thread is paused, show suspend notification ''' # i.e.: stopping at breakpoint thread_info1 = _ThreadInfo() single_notification_behavior.increment_suspend_time() thread_info1.state = STATE_SUSPEND t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_SET_BREAK) # i.e.: stop because of breakpoint thread_info2 = _ThreadInfo() thread_info2.state = STATE_SUSPEND t2 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info2, CMD_SET_BREAK) wait_for_notification(notification_queue, 'suspend') # i.e.: step over (thread 2 is still suspended and this one never completes) thread_info1.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t1) # On pause we should notify that the thread 2 is suspended (after timeout if no other thread suspends first). single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND wait_for_notification(notification_queue, 'suspend') thread_info2.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t2) assert notification_queue.qsize() == 0 assert not single_notification_behavior._suspended_thread_ids # Now, no threads are running and pause is pressed # (maybe we could do a thread dump in this case as this # means nothing is stopped after pause is requested and # the timeout elapses). single_notification_behavior.increment_suspend_time() single_notification_behavior.on_pause() thread_info1.state = STATE_SUSPEND thread_info2.state = STATE_SUSPEND time.sleep(single_notification_behavior.NOTIFY_OF_PAUSE_TIMEOUT * 2) assert notification_queue.qsize() == 0 t1 = run_as_pydevd_daemon_thread(single_notification_behavior.do_wait_suspend, thread_info1, CMD_THREAD_SUSPEND) wait_for_notification(notification_queue, 'suspend') thread_info1.state = STATE_RUN wait_for_notification(notification_queue, 'resume') join_thread(t1) assert notification_queue.qsize() == 0