-
-
Save pganssle/d6587d68306ce19df65dfa2eace40f89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
barrier = threading.Barrier(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import sys | |
import time | |
import locker | |
def worker1(): | |
import mod1 | |
print(f"Worker 1: {mod1.val}") | |
def worker2(): | |
import sys | |
mod1 = sys.modules.get('mod1', None) | |
if mod1 is None: | |
import mod1 | |
print("Worker 2: No problems") | |
else: | |
print(f"Worker 2: {mod1.val}") | |
threading.Thread(target=worker1).start() | |
threading.Thread(target=worker2).start() | |
time.sleep(0.1) | |
locker.barrier.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locker | |
locker.barrier.wait() | |
val = "Forbidden variable" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment