• 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定时器
  • 相关阅读:
    修改器 $set 设置某个键的值 ,修改器 $unset 删除某个键
    修改器 $inc 增加和减少
    IIS 7.5 Express配置文件解析
    MongoDB 安装
    GUID 字符串,16位字符串,19位数字
    MongoDB Shell 学习
    数组修改器 $push $ne ($addToSet $each ) $pop $pull
    但行好事,莫问前程!
    gitlab使用过程中的需求与解决
    [其它] 为什么中国的程序员技术偏低
  • 原文地址:https://www.cnblogs.com/guotianbao/p/9265703.html
Copyright © 2020-2023  润新知