Multiprocess Support
sknepal opened this issue · 4 comments
Hi, does Terminado somehow mess with the multiprocess support provided by Tornado? I'm getting RuntimeError: Cannot run in multiple processes: IOLoop instance has already been initialized. You cannot call IOLoop.instance() before calling start_processes()
error while trying to implement multiprocess as shown here. It works fine with single process.
What gave the above error is this:
import tornado.web
from tornado.ioloop import IOLoop
from terminado import TermSocket, UniqueTermManager
import tornado.httpserver
if __name__ == '__main__':
term_manager = UniqueTermManager(shell_command=["rbash"])
handlers = [
(r"/websocket", TermSocket, {'term_manager': term_manager}),
(r"/()", tornado.web.StaticFileHandler, {'path':'index.html'}),
(r"/(.*)", tornado.web.StaticFileHandler, {'path':'.'}),
]
try:
app = tornado.web.Application(handlers,debug=False,autoreload=False)
server = tornado.httpserver.HTTPServer(app)
server.bind(8079)
server.start(0)
IOLoop.current().start()
finally:
term_manager.shutdown()
Can you please provide an example usage of Terminado with Multiprocess and/or Multithread support? Thank you!
I had no idea that tornado had specific multiprocess support. The manager object needs a reference to the IOLoop, so instantiating that gets the current IOLoop, which appears to be what causes the problem.
Looking at those docs, I think you should be able to use the 'advanced multi-process' interface it describes.
@takluyver I did try the sample code of the 'advanced multi-process' mentioned there, but it also resulted in the same error. Do you think I need to make any changes to it (specifically for Terminado's case) ? Can you please look into supporting it? Thank you.
I suspect you'll need to call fork_processes()
before you create term_manager
.
Thank you it does not show the error now.
But, I am having another issue. I am using Terminado as a backend for xtermjs to make terminal accessible on the web. Instead of directly running rbash, I am using a jailed terminal by using firejail (i.e. term_manager = UniqueTermManager(shell_command=["firejail","rbash"]
). The problem is, firejail does not exit when the client closes the tab/window. It does not appear as a zombie process either, its pretty much active. Can you please point me to the write direction?
Edit: Seems like its a Firejail issue. I'll put the question there; but if you have a solution to handle it via Terminado, please share. Thanks!