fifo.py 864 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #! /usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. # vim:fenc=utf-8:
  4. """Queues are using to enqueue some actions which will be performed after
  5. a task execution."""
  6. from Queue import Queue
  7. def put(action, parameters=()):
  8. """Enqueue one action with action parameters in environment"""
  9. if "mico_queue" in env:
  10. env["mico_queue"].put((action,parameters))
  11. else:
  12. env["mico_queue"] = Queue()
  13. env["mico_queue"].put((action,parameters))
  14. def run():
  15. """Run enqueued actions"""
  16. if "mico_queue" in env:
  17. ret = []
  18. q = env["mico_queue"]
  19. while not q.empty():
  20. action, parameters = q.get()
  21. ret.append(action(*parameters))
  22. return ret
  23. return []
  24. def get():
  25. """Get an element of the queue"""
  26. if "mico_queue" in env:
  27. q = env["mico_queue"]
  28. return q.get()