File: _debugger_case_deadlock_thread_eval.py

package info (click to toggle)
pydevd 3.3.0%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,892 kB
  • sloc: python: 77,508; cpp: 1,869; sh: 368; makefile: 50; ansic: 4
file content (72 lines) | stat: -rw-r--r-- 1,533 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'''
The idea here is that a secondary thread does the processing of instructions,
so, when all threads are stopped, doing an evaluation for:

processor.process('xxx')

would be locked until secondary threads start running.
See: https://github.com/microsoft/debugpy/issues/157
'''

import threading
try:
    from queue import Queue
except:
    from Queue import Queue


class EchoThread(threading.Thread):

    def __init__(self, queue):
        threading.Thread.__init__(self)
        self._queue = queue
        self.started = threading.Event()

    def run(self):
        self.started.set()
        while True:
            obj = self._queue.get()
            if obj == 'finish':
                break

            print('processed', obj.value)
            obj.event.set()  # Break here 2


class NotificationObject(object):

    def __init__(self, value):
        self.value = value
        self.event = threading.Event()


class Processor(object):

    def __init__(self, queue):
        self._queue = queue

    def process(self, i):
        obj = NotificationObject(i)
        self._queue.put(obj)
        assert obj.event.wait()

    def finish(self):
        self._queue.put('finish')


def main():
    queue = Queue()
    echo_thread = EchoThread(queue)
    processor = Processor(queue)
    echo_thread.start()
    echo_thread.started.wait()

    processor.process(1)  # Break here 1
    processor.process(2)
    processor.process(3)
    processor.finish()


if __name__ == '__main__':
    main()
    print('TEST SUCEEDED!')