main.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. '''This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
  2. Copyright 2011 by the AToMPM team and licensed under the LGPL
  3. See COPYING.lesser and README.md in the root of this project for full details'''
  4. import asyncore, logging, threading
  5. from httpd import HTTPServerThread
  6. from ws import WebSocket
  7. '''
  8. init and launch http server and asyncore loop + set logging level for mt/*
  9. NOTE: omitting asyncore.loop()'s first parameter ('timeout' according to the
  10. API) causes initialization to be very long... it seems it represents
  11. the delay during which an asyncore loop may remain idle before giving
  12. control to someone
  13. NOTE: python-websocket is built on an event-loop called asyncore... this loop
  14. is started via asyncore.loop()... unfortunately, if there isn't already
  15. something in the loop when it's started, it just terminates... hence,
  16. to enable the creation of WebSockets (which requires a running asyncore
  17. loop) in each future mtworker, we create a dummy WebSocket which serves
  18. only to keep the asyncore loop alive while there are no other open
  19. WebSockets '''
  20. def main() :
  21. logging.basicConfig(format='%(levelname)s - %(message)s', level=logging.INFO)
  22. dummy_ws = WebSocket()
  23. httpd = HTTPServerThread()
  24. httpd.start()
  25. try :
  26. asyncore.loop(1)
  27. except KeyboardInterrupt :
  28. # print(threading.enumerate())
  29. httpd.stop()
  30. dummy_ws.close()
  31. pass
  32. if __name__ == "__main__" :
  33. main()