Skip to content
Permalink
Browse files

server2: rework shell

This patch fixes multiple errors when running server2 in shell mode

Signed-off-by: Florian Scherf <f.scherf@pengutronix.de>
  • Loading branch information
fscherf committed Dec 4, 2019
1 parent c389d12 commit 695341d3c60e282d9e19457457e6d88e16a679b2
Showing with 39 additions and 8 deletions.
  1. +12 −0 bin/_flamingo-server2
  2. +25 −7 flamingo/server2/server.py
  3. +2 −1 setup.py
@@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-

import logging
import signal
import os

from flamingo.server2.logging import RPCHandler

@@ -23,6 +25,8 @@ parser = gen_default_parser(prog='flamingo-server2')

parser.add_argument('--port', type=int, default=8080)
parser.add_argument('--host', type=str, default='localhost')
parser.add_argument('--shell', action='store_true')
parser.add_argument('--shell-history', action='store_true')

namespace, settings = parse_args(parser, setup_logging=False)

@@ -51,6 +55,14 @@ try:
except KeyboardInterrupt:
exit()

# setup shell
if namespace.shell:
def start_shell(server):
server.start_shell(history=namespace.shell_history)
os.kill(os.getpid(), signal.SIGTERM)

loop.create_task(server.rpc.worker_pool.run(start_shell, server))

# run
print('starting server on http://localhost:{}/'.format(namespace.port))

@@ -19,6 +19,7 @@

try:
import IPython
from traitlets.config import Config

IPYTHON = True

@@ -41,6 +42,7 @@ def __init__(self, app, settings, rpc_logging_handler, loop=None,
self.logger = logger

# locks
self._shell_running = False
self._locked = False
self._pending_locks = []

@@ -247,15 +249,31 @@ def get_meta_data(self, request, url):

return meta_data

def start_shell(self, request):
context = self.context # NOQA
history = self.history # NOQA
def start_shell(self, request=None, history=False):
if self._shell_running:
return

self._shell_running = True

try:
if IPYTHON:
config = Config()

if IPYTHON:
IPython.embed()
if not history:
# this is needed to avoid sqlite errors while running in
# a multithreading environment
config.HistoryAccessor.enabled = False

else:
code.interact(local=globals())
context = self.context # NOQA
history = self.history # NOQA

IPython.embed(config=config)

else:
code.interact(local=globals())

finally:
self._shell_running = False

# watcher events ##########################################################
def handle_watcher_events(self, events):
@@ -17,6 +17,7 @@
'live-server': [
'aiohttp-json-rpc==0.12.1',
'pygments',
'ipython<7',
],
'chardet': [
'chardet',
@@ -40,7 +41,7 @@
'coloredlogs',
],
'ipython': [
'ipython',
'ipython<7',
]
}

0 comments on commit 695341d

Please sign in to comment.
You can’t perform that action at this time.