Hi!
I am trying to develop a service that can be called from command line and behave like a terminal.
All I type (stdin) is passed to remote service for execution, and the result is sent me back to print out to stdout.
Here is the code:
import logging
from nameko.extensions import Entrypoint
from nameko.rpc import RpcProxy
logger = logging.getLogger(__name__)
class StdinReader(Entrypoint):
def start(self):
self.container.spawn_managed_thread(self.run)
def run(self):
while True:
s = input()
self.handle_read(s)
def handle_read(self, cmd):
logger.info('Handle read %s', cmd)
self.container.spawn_worker(self, (cmd,), {})
stdin = StdinReader.decorator
class TerminalBroker:
name = 'terminal'
asterisk = RpcProxy('asterisk')
@stdin
def read(self, cmd):
logger.info('Read here %s', cmd)
res = self.asterisk.cli_command(cmd)
print(res)
I have now 2 problems here:
- “Handle read” is logged, but “Read here” is not. So this is like container.spawn_worker does not call the worker method read.
- How to fully eliminate any stdout output from nameko run?
/services # nameko run terminal_broker --config=config.yml
2019-10-19 11:16:28,892 - nameko.messaging:227 - DEBUG - starting <QueueConsumer at 0x7f04173183d0>
2019-10-19 11:16:28,892 - nameko.messaging:231 - DEBUG - waiting for consumer ready <QueueConsumer at 0x7f04173183d0>
hello
2019-10-19 11:16:30,883 - terminal_broker:18 - INFO - Handle read hello