race condition python

Solutions on MaxInterview for race condition python by the best coders in the world

showing results for - "race condition python"
Sofia
11 Sep 2019
1import threading
2import time
3
4def test_this():
5    print("some")
6    time.sleep(0.100)
7    print("message")
8
9note = [threading.Thread(target=test_this) for _ in range(2)]
10[_.start() for _ in note]
11
12
13"""
14One of the sample Output:
15
16some
17some
18messagemessage
19
20"""
21
22"""
23What's happening:
24----------------
25
26All threads try to access global print(), and print() responds by printing the some messages in single line
27(those are from threads trying to access the print() at the same time)
28
29and then prints the /n after that (see many blank lines)
30"""
31