def test_start_new_thread2(self):
        pydev_monkey.patch_thread_modules()
        try:
            found = {}

            class F(object):
                start_new_thread = thread.start_new_thread

                def start_it(self):
                    try:
                        self.start_new_thread(self.function, (1,2,3,4), {'d':1, 'e':2})
                    except:
                        import traceback;traceback.print_exc()

                def function(self, a, b, *args, **kwargs):
                    found['a'] = a
                    found['b'] = b
                    found['args'] = args
                    found['kwargs'] = kwargs

            f = F()
            f.start_it()
            import time
            for _i in xrange(20):
                if len(found) == 4:
                    break
                time.sleep(.1)
            else:
                raise AssertionError('Could not get to condition before 2 seconds')

            self.assertEqual({'a': 1, 'b': 2, 'args': (3, 4), 'kwargs': {'e': 2, 'd': 1}}, found)
        finally:
            pydev_monkey.undo_patch_thread_modules()
    def test_start_new_thread2(self):
        pydev_monkey.patch_thread_modules()
        try:
            found = {}

            class F(object):
                start_new_thread = _thread.start_new_thread

                def start_it(self):
                    try:
                        self.start_new_thread(self.function, (1,2,3,4), {'d':1, 'e':2})
                    except:
                        import traceback;traceback.print_exc()

                def function(self, a, b, *args, **kwargs):
                    found['a'] = a
                    found['b'] = b
                    found['args'] = args
                    found['kwargs'] = kwargs

            f = F()
            f.start_it()
            import time
            for _i in range(20):
                if len(found) == 4:
                    break
                time.sleep(.1)
            else:
                raise AssertionError('Could not get to condition before 2 seconds')

            self.assertEqual({'a': 1, 'b': 2, 'args': (3, 4), 'kwargs': {'e': 2, 'd': 1}}, found)
        finally:
            pydev_monkey.undo_patch_thread_modules()
    def test_start_new_thread(self):
        pydev_monkey.patch_thread_modules()
        try:
            found = {}

            def function(a, b, *args, **kwargs):
                found['a'] = a
                found['b'] = b
                found['args'] = args
                found['kwargs'] = kwargs

            thread.start_new_thread(function, (1, 2, 3, 4), {'d': 1, 'e': 2})
            import time
            for _i in xrange(20):
                if len(found) == 4:
                    break
                time.sleep(.1)
            else:
                raise AssertionError(
                    'Could not get to condition before 2 seconds')

            self.assertEqual(
                {
                    'a': 1,
                    'b': 2,
                    'args': (3, 4),
                    'kwargs': {
                        'e': 2,
                        'd': 1
                    }
                }, found)
        finally:
            pydev_monkey.undo_patch_thread_modules()
    def test_start_new_thread(self):
        pydev_monkey.patch_thread_modules()
        try:
            found = {}
            def function(a, b, *args, **kwargs):
                found['a'] = a
                found['b'] = b
                found['args'] = args
                found['kwargs'] = kwargs
            thread.start_new_thread(function, (1,2,3,4), {'d':1, 'e':2})
            import time
            for _i in xrange(20):
                if len(found) == 4:
                    break
                time.sleep(.1)
            else:
                raise AssertionError('Could not get to condition before 2 seconds')

            self.assertEqual({'a': 1, 'b': 2, 'args': (3, 4), 'kwargs': {'e': 2, 'd': 1}}, found)
        finally:
            pydev_monkey.undo_patch_thread_modules()
Пример #5
0
    def attachment_entry():
        # The client will retry the connection a few times to avoid the inherent
        # raciness of this.
        debugpy.listen(_dap_port)

        # Debugger tracing isn't needed for just tracebacks, but if full debugging
        # is needed then it needs to be re-enabled while debugging.
        # We want to use `pydevd.stoptrace` but if this is called before we have
        # connected to the debug adapter from the client then it'll send a
        # terminate to the adapter and the adapter will auto-exit before we can
        # connect to it. After the connection then it's OK to terminate since the
        # adapter will not close while there are active connections.
        threading.settrace(None)  # for all future threads
        try:
            # Stop debugpy from tracing newly created threads.
            from _pydev_bundle import pydev_monkey  # pylint: disable=g-import-not-at-top
            pydev_monkey.undo_patch_thread_modules()
        except ModuleNotFoundError:
            # _pydev_bundle may be vendored into either location.
            from debugpy.third_party.pydevd._pydev_bundle import pydev_monkey  # pylint: disable=g-import-not-at-top
            pydev_monkey.undo_patch_thread_modules()

        # Clear the trace flag to allow fetching stack traces.
        main_thread.pydev_do_not_trace = False