Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import time
- def frotz(new_baz_value):
- class Wilma:
- baz = 42
- print(f"I am thread #{threading.get_ident()} and the initial value of my Wilma.baz is {Wilma.baz}")
- Wilma.baz = new_baz_value
- print(f"I am thread #{threading.get_ident()} and my Wilma.baz has been changed to {Wilma.baz}")
- for i in range(3):
- threading.Thread(target=frotz, args=(i,)).start()
- time.sleep(0.1)
- """Result:
- I am thread #17212 and the initial value of my Wilma.baz is 42
- I am thread #17212 and my Wilma.baz has been changed to 0
- I am thread #28744 and the initial value of my Wilma.baz is 42
- I am thread #28744 and my Wilma.baz has been changed to 1
- I am thread #17268 and the initial value of my Wilma.baz is 42
- I am thread #17268 and my Wilma.baz has been changed to 2
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement