Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server side call client side callback function not work #545

Open
cocobase opened this issue Oct 25, 2023 · 1 comment
Open

server side call client side callback function not work #545

cocobase opened this issue Oct 25, 2023 · 1 comment

Comments

@cocobase
Copy link

I define a client/server RPC service, from server side, I will call client side's function on timer.
Everything is ok ,but when I invoke async callback, it does not work.

I can see print(data) in function on_tick output right data
But at client side, I can't see any output in funciton on_event

Why?

Environment
  • rpyc newest
  • python 3.6
  • operating Windows11
Minimal example

Server Service

class MyServiceFactory(rpyc.Service, metaclass=MetaBase):

    class exposed_MyTickService(object):   # exposing names is not limited to methods :)

        def __init__(self, code_list, callback):
            print(f"news client with {code_list}  and {str(callback)} and ctx {MyServiceFactory.ctx}")
            self.code_list = code_list
            self.callback = rpyc.async_(callback)   # create an async callback
            # 调用订阅
            self.sub_id = getattr(MyServiceFactory.ctx, "subscribe_whole_quote")(code_list, self.on_tick)
            print(self.sub_id)

        def on_tick(self, data):
            print(data)
            self.callback(data)

        def exposed_stop(self):   # this method has to be exposed too
            print("处理tick订阅取消")
            getattr(MyServiceFactory.ctx, "unsubscribe_quote")(self.sub_id)

Client:

lass MyClient(object):

    def __init__(self):
        self.conn = rpyc.connect("localhost", 18810)
        self.bgsrv = rpyc.BgServingThread(self.conn)
        self.root = self.conn.root
        self.service = self.root.MyTickService(["600036.SH"], self.on_event)  

    def on_event(self, tick_data):
        print(f"tick: {tick_data}")

    def close(self):
        self.service.stop()
        self.bgsrv.stop()
        self.conn.close()


if __name__ == "__main__":

    client = MyClient()
    sleep(20)
    client.close()
@cocobase
Copy link
Author

Additional Information:
I change code in server side, do not use async call, when I call client side function directory, I got a lot of error message. please see attachment.
屏幕截图 2023-10-25 112248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant