Advertisement
Guest User

Untitled

a guest
Nov 1st, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import threading
  2. import time
  3. def frotz(new_baz_value):
  4. class Wilma:
  5. baz = 42
  6. print(f"I am thread #{threading.get_ident()} and the initial value of my Wilma.baz is {Wilma.baz}")
  7. Wilma.baz = new_baz_value
  8. print(f"I am thread #{threading.get_ident()} and my Wilma.baz has been changed to {Wilma.baz}")
  9.  
  10. for i in range(3):
  11. threading.Thread(target=frotz, args=(i,)).start()
  12. time.sleep(0.1)
  13.  
  14. """Result:
  15.  
  16. I am thread #17212 and the initial value of my Wilma.baz is 42
  17. I am thread #17212 and my Wilma.baz has been changed to 0
  18. I am thread #28744 and the initial value of my Wilma.baz is 42
  19. I am thread #28744 and my Wilma.baz has been changed to 1
  20. I am thread #17268 and the initial value of my Wilma.baz is 42
  21. I am thread #17268 and my Wilma.baz has been changed to 2
  22. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement