(Multi-Threading Python) Print 1 to 10 numbers alternatively, using two threads
20:38 10 Nov 2019

Please help me in resolving below Deadlock situation while printing 1 to 10 numbers alternatively, using two threads.

And please tell me the best practices to avoid deadlock situation in multi-threading python.

from threading import *

c = Condition()

def thread_1():
    c.acquire()
    for i in range(1, 11, 2):
        print(i)
        c.notify()
        c.wait()
    c.release()
    c.notify()

def thread_2():
    c.acquire()
    c.wait()
    for i in range(2, 11, 2):
        print(i)
        c.notify()
        c.wait()
    c.release()


t1 = Thread(target=thread_1)
t2 = Thread(target=thread_2)

t1.start()
t2.start()
python multithreading deadlock