File: custom_exec.py

package info (click to toggle)
terminado 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 300 kB
  • sloc: python: 813; makefile: 152; javascript: 56; sh: 2
file content (43 lines) | stat: -rw-r--r-- 1,388 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Using a custom thread pool for subprocess writes.
"""
from concurrent import futures

import tornado.web

# This demo requires tornado_xstatic and XStatic-term.js
import tornado_xstatic
from common_demo_stuff import STATIC_DIR, TEMPLATE_DIR, run_and_show_browser

from terminado import SingleTermManager, TermSocket


class TerminalPageHandler(tornado.web.RequestHandler):
    def get(self):
        return self.render(
            "termpage.html",
            static=self.static_url,
            xstatic=self.application.settings["xstatic_url"],
            ws_url_path="/websocket",
        )


def main(argv):
    with futures.ThreadPoolExecutor(max_workers=2) as custom_exec:
        term_manager = SingleTermManager(shell_command=["bash"], blocking_io_executor=custom_exec)
        handlers = [
            (r"/websocket", TermSocket, {"term_manager": term_manager}),
            (r"/", TerminalPageHandler),
            (r"/xstatic/(.*)", tornado_xstatic.XStaticFileHandler, {"allowed_modules": ["termjs"]}),
        ]
        app = tornado.web.Application(
            handlers,
            static_path=STATIC_DIR,
            template_path=TEMPLATE_DIR,
            xstatic_url=tornado_xstatic.url_maker("/xstatic/"),
        )
        app.listen(8765, "localhost")
        run_and_show_browser("http://localhost:8765/", term_manager)


if __name__ == "__main__":
    main([])