Created
November 26, 2020 16:45
-
-
Save gentlegiantJGC/773e601099c70cd0457d61d3342e5b77 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from threading import Thread, get_ident | |
import time | |
# ThreadingEnabled = False | |
ThreadingEnabled = True | |
def main(): | |
class DummyObj: | |
def __init__(self): | |
self._loaded = False | |
def setup(self): | |
if not self._loaded: | |
print(f"setting up from thread {get_ident()}") | |
time.sleep(3) | |
print(f"finished setting up from thread {get_ident()}") | |
self._loaded = True | |
else: | |
print("Already set up", get_ident()) | |
dummy_obj = DummyObj() | |
if ThreadingEnabled: | |
thread = Thread(target=dummy_obj.setup) | |
thread.start() | |
else: | |
dummy_obj.setup() | |
dummy_obj.setup() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment