pyjsonrpc模块使用

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

# -*- coding:utf-8 -*- 
#!/usr/bin/env python2.7
# @Author  : tianbao
# @Contact : [email protected]
# @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 : [email protected]
# @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定时器

 

你可能感兴趣的:(pyjsonrpc模块使用)