main.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. '''*****************************************************************************
  2. AToMPM - A Tool for Multi-Paradigm Modelling
  3. Copyright (c) 2011 Raphael Mannadiar (raphael.mannadiar@mail.mcgill.ca)
  4. This file is part of AToMPM.
  5. AToMPM is free software: you can redistribute it and/or modify it under the
  6. terms of the GNU Lesser General Public License as published by the Free Software
  7. Foundation, either version 3 of the License, or (at your option) any later
  8. version.
  9. AToMPM is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with AToMPM. If not, see <http://www.gnu.org/licenses/>.
  14. *****************************************************************************'''
  15. import asyncore, logging, threading
  16. from httpd import HTTPServerThread
  17. from ws import WebSocket
  18. '''
  19. init and launch http server and asyncore loop + set logging level for mt/*
  20. NOTE: omitting asyncore.loop()'s first parameter ('timeout' according to the
  21. API) causes initialization to be very long... it seems it represents
  22. the delay during which an asyncore loop may remain idle before giving
  23. control to someone
  24. NOTE: python-websocket is built on an event-loop called asyncore... this loop
  25. is started via asyncore.loop()... unfortunately, if there isn't already
  26. something in the loop when it's started, it just terminates... hence,
  27. to enable the creation of WebSockets (which requires a running asyncore
  28. loop) in each future mtworker, we create a dummy WebSocket which serves
  29. only to keep the asyncore loop alive while there are no other open
  30. WebSockets '''
  31. def main() :
  32. logging.basicConfig(format='%(levelname)s - %(message)s', level=logging.INFO)
  33. dummy_ws = WebSocket()
  34. httpd = HTTPServerThread()
  35. httpd.start()
  36. try :
  37. asyncore.loop(1)
  38. except KeyboardInterrupt :
  39. # print(threading.enumerate())
  40. httpd.stop()
  41. dummy_ws.close()
  42. pass
  43. if __name__ == "__main__" :
  44. main()