Worker.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. from threading import Thread, Lock
  3. import time
  4. from aman.config.Airport import Airport
  5. class Worker(Thread):
  6. def __init__(self):
  7. Thread.__init__(self)
  8. self.stopThread = None
  9. self.icao = None
  10. self.configuration = None
  11. self.arrivalRoutes = None
  12. self.updateLock = None
  13. self.reportQueue = {}
  14. def __del__(self):
  15. self.release()
  16. def acquire(self, icao : str, configuration : Airport):
  17. self.stopThread = None
  18. self.icao = icao
  19. self.configuration = configuration
  20. self.arrivalRoutes = configuration.gngData.arrivalRoutes
  21. self.updateLock = Lock()
  22. self.reportQueue = {}
  23. self.start()
  24. def acquireLock(self):
  25. if None != self.updateLock:
  26. self.updateLock.acquire()
  27. def release(self):
  28. self.stopThread = True
  29. self.join()
  30. def releaseLock(self):
  31. if None != self.updateLock:
  32. self.updateLock.release()
  33. def run(self):
  34. counter = 0
  35. while None == self.stopThread:
  36. time.sleep(1)
  37. counter += 1
  38. if 0 != (counter % 60):
  39. continue
  40. # TODO handle the report queue and update internal information
  41. # TODO execute planning, etc.
  42. continue