msgpack-rpc / msgpack-rpc-python

MessagePack RPC implementation for Python
205 stars 72 forks source link

Example of using notify() #12

Closed dniku closed 8 years ago

dniku commented 9 years ago

I couldn't get client.notify() to work. It looks like the call is going nowhere. The following code prints nothing:

import multiprocessing, time
import msgpackrpc

class SumServer(object):
    def notification(self, s):
        print(s)

def server():
    server = msgpackrpc.Server(SumServer())
    server.listen(msgpackrpc.Address("localhost", 4000))
    server.start()

def client():
    client = msgpackrpc.Client(msgpackrpc.Address("localhost", 4000))
    client.notify('notification', 'boo')

def main():
    proc_server = multiprocessing.Process(target=server)
    proc_server.start()

    time.sleep(0.5)

    try:
        client()
    finally:
        proc_server.terminate()

if __name__ == '__main__':
    main()

Are there any examples of using .notify()?

repeatedly commented 8 years ago

It worked when separate your code into 2 modules. So your code is something wrong.

repeatedly commented 8 years ago

This seems not msgpack-rpc-python issue. Closed.

dniku commented 8 years ago

Could you provide an example of working notify() code?

repeatedly commented 8 years ago

Server:

import msgpackrpc

class SumServer(object):
    def notification(self, s):
        print(s)

server = msgpackrpc.Server(SumServer())
server.listen(msgpackrpc.Address("localhost", 4000))
server.start()

Client:

import msgpackrpc

client = msgpackrpc.Client(msgpackrpc.Address("localhost", 4000))
client.notify('notification', 'boo')