python:cmd+zeromq
2022/1/26 17:04:52
本文主要是介绍python:cmd+zeromq,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#https://blog.51cto.com/capricorn/1891402 # coding=utf-8 from cmd import * import sys from subreqnode import SubReqNode from multiprocessing import Queue, Process def subscribe_callback(node): string = node.sub_socket.recv_string() print('{}'.format(string)) def start(): node = SubReqNode("tcp://127.0.0.1:55566", "tcp://127.0.0.1:55567") node.subscribe('onu/online') node.start(subscribe_callback) p = Process(target=start) p.start() class TestCmd(Cmd): def __init__(self): Cmd.__init__(self) Cmd.intro="test module" def do_test1(self,line): print "test test" def help_test1(self): print "test the module" def preloop(self): print u"enter test module" def postloop(self): print u"exit test module" def do_exit(self,line): return True def help_exit(self): print "exit command, return main loop" def do_quit(self,line): return True def help_quit(self): print "return main loop" class MyShell(Cmd): def __init__(self): Cmd.__init__(self) self.prompt="Oxo>" self.intro=""" test cmd package all exit """ self.doc_header=",modify header " self.doc_leader='it is a leader' #node = SubReqNode("tcp://127.0.0.1:55566", "tcp://127.0.0.1:55567") #node.subscribe('onu/online') #self.node = node #self.process = Process(target=node.start, args=(subscribe_callback,)) def preloop(self): print u"welcome info" def postloop(self): print u"post loop" #def precmd(self, line): # print "print this line before do a command" # return Cmd.precmd(self, line) # def postcmd(self, stop, line): # print "print this line after do a command" # return Cmd.postcmd(self, stop, line) def do_hello(self,line): print u"hello" print line def help_hello(self): print u"hello ~~~" def complete_hello(self,text,line,begidx,endidx): if not text:# completions=['timo','jack','jams'] return completions else: completions=['timo','jack','jams'] return [i for i in completions if i.startswith(text)] def do_test(self, line): i=TestCmd() i.prompt=self.prompt[:-1] +':Test>' i.cmdloop() def help_test(self): print u"it is a test" def do_exit(self,line): print u"exit!!" return True def help_exit(self): print "exit the ~~" def emptyline(self): pass def default(self,line): print u"no the command" MyShell().cmdloop()
这篇关于python:cmd+zeromq的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-03用FastAPI掌握Python异步IO:轻松实现高并发网络请求处理
- 2025-01-02封装学习:Python面向对象编程基础教程
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型