messagebus/service/__main__.py
Go to the documentation of this file.
1 # Copyright 2017 Mycroft AI Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 from tornado import autoreload, web, ioloop
16 
17 from mycroft.configuration import Configuration
18 from mycroft.lock import Lock # creates/supports PID locking file
19 from mycroft.messagebus.service.ws import WebsocketEventHandler
20 from mycroft.util import validate_param, reset_sigint_handler, create_daemon, \
21  wait_for_exit_signal
22 
23 settings = {
24  'debug': True
25 }
26 
27 
28 def main():
29  import tornado.options
31  lock = Lock("service")
32  tornado.options.parse_command_line()
33 
34  def reload_hook():
35  """ Hook to release lock when autoreload is triggered. """
36  lock.delete()
37 
38  autoreload.add_reload_hook(reload_hook)
39 
40  config = Configuration.get().get("websocket")
41 
42  host = config.get("host")
43  port = config.get("port")
44  route = config.get("route")
45  validate_param(host, "websocket.host")
46  validate_param(port, "websocket.port")
47  validate_param(route, "websocket.route")
48 
49  routes = [
50  (route, WebsocketEventHandler)
51  ]
52  application = web.Application(routes, **settings)
53  application.listen(port, host)
54  create_daemon(ioloop.IOLoop.instance().start)
55 
57 
58 
59 if __name__ == "__main__":
60  main()
def create_daemon(target, args=(), kwargs=None)
def validate_param(value, name)
def get(phrase, lang=None, context=None)


mycroft_ros
Author(s):
autogenerated on Mon Apr 26 2021 02:35:40