Skip to content

Instantly share code, notes, and snippets.

@gentlegiantJGC
Created November 26, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gentlegiantJGC/773e601099c70cd0457d61d3342e5b77 to your computer and use it in GitHub Desktop.
Save gentlegiantJGC/773e601099c70cd0457d61d3342e5b77 to your computer and use it in GitHub Desktop.
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