Guest User

Untitled

a guest
Feb 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. class AsyncJsonDescriptionReader:
  2. file = None
  3. locker = None
  4.  
  5. def read(self):
  6. AsyncJsonDescriptionReader.locker.acquire()
  7. string = AsyncJsonDescriptionReader.file.readline()
  8. AsyncJsonDescriptionReader.locker.release()
  9. if len(string) > 0:
  10. return self.transformer.transform(json.loads(string))
  11. else:
  12. return None
  13.  
  14. def __init__(self, description_path, ind):
  15. self.ind = ind
  16. if AsyncJsonDescriptionReader.locker is None:
  17. AsyncJsonDescriptionReader.locker = Lock()
  18. if AsyncJsonDescriptionReader.file is None:
  19. AsyncJsonDescriptionReader.file = open(description_path, 'r')
  20. print(id(AsyncJsonDescriptionReader.locker), id(AsyncJsonDescriptionReader.file))
  21. self.transformer = JSON2ClassTransformer()
Add Comment
Please, Sign In to add comment