• Title


      pyjsonrpc模块的远程过程调用方法。

    # -*- coding:utf-8 -*- 
    #!/usr/bin/env python2.7
    # @Author  : tianbao
    # @Contact : gmu1592618@gmail.com
    # @Time    : 2018/7/4 21:49
    # @File    : aactest.py
    # @Software: PyCharm
    import pyjsonrpc
    
    http_client = pyjsonrpc.HttpClient(
        url = "http://example.com/jsonrpc",
        username = "Username",
        password = "Password"
    )
    # 第一种调用方法
    print http_client.call("add", 1, 2)
    # Result: 3
    
    # 第二种调用方法
    # It is also possible to use the *method* name as *attribute* name.
    print http_client.add(1, 2)
    # Result: 3
    
    # 没有返回值
    # Notifications send messages to the server, without response.
    http_client.notify("add", 3, 4)
    client
    # -*- coding:utf-8 -*- 
    #!/usr/bin/env python2.7
    # @Author  : tianbao
    # @Contact : gmu1592618@gmail.com
    # @Time    : 2018/7/4 21:49
    # @File    : aastest.py
    # @Software: PyCharm
    import pyjsonrpc
    
    
    class RequestHandler(pyjsonrpc.HttpRequestHandler):
    
        @pyjsonrpc.rpcmethod
        def add(self, a, b):
            """Test method"""
            return a + b
    
    
    # Threading HTTP-Server
    http_server = pyjsonrpc.ThreadingHttpServer(
        server_address = ('localhost', 8080),  # 监听地址
        RequestHandlerClass = RequestHandler
    )
    print "Starting HTTP server ..."
    print "URL: http://localhost:8080"
    http_server.serve_forever()                 # 启动
    server
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import pygtk
    pygtk.require('2.0')
    import gtk
    import sys
    import os
    import random
    import gobject
    
    from debug import log
    from cusdialog import DialogWith1Button
    
    class A(object):
        def __init__(self):
            self.wait_times=0
    
        btn1_dlg = DialogWith1Button(btn1_label="关闭")
        btn1_dlg.set_label_text("正在启动,请稍候。。。")
        # btn1_dlg.msg_dialog.set_transient_for(self.win)
    
        def wait_timeout(self,btn1_dlg, max_times):
            self.wait_times += random.randint(1, 5)
            if self.wait_times > max_times:
                btn1_dlg.btn_ok.clicked()
                return False
            btn1_dlg.set_label_text("正在启动,请稍候。。。(%s%%)" %
                                    (self.wait_times*100/max_times,))
            return True
    
    
    if __name__ == '__main__':
        a=A()
    
        gobject.timeout_add(1000, a.wait_timeout, a.btn1_dlg, 100)
    
        a.btn1_dlg.run()
    ptgtk记时器
    from apscheduler.schedulers.blocking import BlockingScheduler
    import datetime
    
    def aps_test():
        print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), '你好'
    
    
    scheduler = BlockingScheduler()
    scheduler.add_job(func=aps_test, trigger='cron', second='*/5')
    scheduler.start()
    apscheduler定时器
  • 相关阅读:
    编译原理 —— 正规式、正规集和正则定义
    NFA的确定化
    第三章 词法分析与有限自动机
    文法:0型【短语文法】、1型【上下文有关文法】、2型【上下文无关文法】、3型【正规文法】
    语法树、短语、直接短语、句柄、素短语、最左素短语
    【第1章 编译概述】1.2编译程序的发展
    【第1章 编译概述】1.2编译的各个阶段
    【第1章 编译概述】1.1 编译程序功能
    【第1章 编译概述】1.1 程序设计语言
    【第9章 目标代码生成】9.3 简单代码生成器
  • 原文地址:https://www.cnblogs.com/guotianbao/p/9265703.html
Copyright © 2020-2023  润新知