Created
October 12, 2018 13:29
-
-
Save ZoranPandovski/a01f81ede283fbf1c895b728b15c28ea to your computer and use it in GitHub Desktop.
Simple object pool example in Python
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
class Pool: | |
'''Manage pool objects''' | |
def __init__(self, size): | |
self._objects = [PoolObject() for i in range(size)] | |
def get_object(self): | |
return self._objects.pop() | |
def release_object(self, obj): | |
self._objects.append(obj) | |
class PoolObject: | |
pass | |
if __name__ == "__main__": | |
pool = Pool(10) | |
obj1 = pool.get_object() | |
pool.release_object(obj1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment