Threading -how do we determine when to run different operations on the same CPU Core. Threading does not involve running on multiple Cores.
def func():
print('ran')
time.sleep(1)
print('done')
time.sleep(0.85)
print("now done")
x = threading.Thread(target=func)
x.start()
print(threading.active_count())
time.sleep(0.9)
print('finally')
.
ls = []
def count(n):
for i in range(1, n+1):
# print(i)
ls.append(i)
time.sleep(0.5)
def count2(n):
for i in range(1, n+1):
# print(i)
ls.append(i)
time.sleep(0.5)
x = threading.Thread(target=count, args=(5,))
x.start()
x.join()
y = threading.Thread(target=count2, args=(5,))
y.start()
# x.join()
y.join()
# print("Done")
# time.sleep(0.5)
print(ls)