Exemple #1
0
    def test_get_running_trace(self):
        ready = threading.Event()
        done = threading.Event()

        def worker():
            inner()

        def inner():
            ready.set()
            done.wait()

        t = concurrent.thread(worker, name="Test")
        t.start()
        try:
            if not ready.wait(1):
                raise RuntimeError("Timeout waiting for worker thread")
            formatted_traceback = concurrent.format_traceback(t.ident)
        finally:
            done.set()
            t.join()

        # The functions called from the worker thread should appear in the
        # traceback.
        self.assertIn("in worker", formatted_traceback)
        self.assertIn("in inner", formatted_traceback)
Exemple #2
0
    def test_get_running_trace(self):
        ready = threading.Event()
        done = threading.Event()

        def worker():
            inner()

        def inner():
            ready.set()
            done.wait()

        t = concurrent.thread(worker, name="Test")
        t.start()
        try:
            if not ready.wait(1):
                raise RuntimeError("Timeout waiting for worker thread")
            formatted_traceback = concurrent.format_traceback(t.ident)
        finally:
            done.set()
            t.join()

        # The functions called from the worker thread should appear in the
        # traceback.
        self.assertIn("in worker", formatted_traceback)
        self.assertIn("in inner", formatted_traceback)
Exemple #3
0
    def test_get_running_trace(self):
        def worker():
            time.sleep(2)

        t = concurrent.thread(worker, name="Test")
        t.start()

        # yield control to let the Test thread to start
        time.sleep(1)
        try:
            formatted_traceback = concurrent.format_traceback(t.ident)

            self.assertIn("time.sleep(2)", formatted_traceback)
        finally:
            t.join()
Exemple #4
0
 def _check_task(self, task_number):
     with self._lock:
         if task_number != self._task_counter:
             return
         if self._task.discard:
             if self._discarded:
                 raise AssertionError("Attempt to discard worker twice")
             self._discarded = True
         else:
             self._scheduled_check = self._check_after(self._task.timeout)
     if self._discarded:
         # Please make sure the executor call is performed outside the lock
         # -- there is another lock involved in the executor and we don't
         # want to fall into a deadlock incidentally.
         self._executor._worker_discarded(self)
         self._log.info("Worker discarded: %s", self)
     else:
         # we want to avoid to log with the lock held, so we do it here.
         try:
             trace = concurrent.format_traceback(self._thread.ident)
         except KeyError:
             trace = "(traceback not available)"
         self._log.warning("Worker blocked: %s, traceback:\n%s", self,
                           trace)
Exemple #5
0
 def _check_task(self, task_number):
     with self._lock:
         if task_number != self._task_counter:
             return
         if self._task.discard:
             if self._discarded:
                 raise AssertionError("Attempt to discard worker twice")
             self._discarded = True
         else:
             self._scheduled_check = self._check_after(self._task.timeout)
     if self._discarded:
         # Please make sure the executor call is performed outside the lock
         # -- there is another lock involved in the executor and we don't
         # want to fall into a deadlock incidentally.
         self._executor._worker_discarded(self)
         self._log.info("Worker discarded: %s", self)
     else:
         # we want to avoid to log with the lock held, so we do it here.
         try:
             trace = concurrent.format_traceback(self._thread.ident)
         except KeyError:
             trace = "(traceback not available)"
         self._log.warning("Worker blocked: %s, traceback:\n%s", self,
                           trace)
Exemple #6
0
 def test_get_wrong_id_trace(self, ident):
     with pytest.raises(KeyError):
         concurrent.format_traceback(ident)