Created
December 4, 2015 03:42
-
-
Save JobsDong/7ee0c1df92658840602d to your computer and use it in GitHub Desktop.
python singleton
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import threading | |
class KbTerms(object): | |
"""singleton | |
""" | |
_instance_lock = threading.Lock() | |
@staticmethod | |
def instance(): | |
if not hasattr(KbTerms, "_instance"): | |
with KbTerms._instance_lock: | |
if not hasattr(KbTerms, "_instance"): | |
setattr(KbTerms, "_instance", KbTerms()) | |
return getattr(KbTerms, "_instance") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment