I want to run two functions in parallel which print two lists in parallel. But what I get is one list, being printed after the other list has completed.
I have tried the following code.
import threading
import time
def fun1():
testz=['z','y','x','w','v','u','t']
for j in testz:
print (j)
time.sleep(1)
def fun2():
test=['a','b','c','d','e','f','g']
for i in test:
print (i)
time.sleep(1)
thread1 = threading.Thread(target=fun1())
thread2 = threading.Thread(target=fun2())
thread1.start()
time.sleep(0.5)
thread2.start()
thread1.join()
thread2.join()
The result that I expect for this is :
z
a
y
b
x
c
w
d
v
e
u
f
t
g
but what I get is :
z
y
x
w
v
u
t
a
b
c
d
e
f
g
which seems like the two threads are being run one after the other.