On Thu, Feb 21, 2013 at 06:10:35PM +0800, ShaoHe Feng wrote:
Hi, Adam
An error arises, when I call json rpc server by AsyncoreReactor. And
I can call json rpc server successfully by a simple TCPReactor write
by myself.
how can I call json Rpc by AsyncoreReactor correctly?
>>> address = ("127.0.0.1", 4044)
>>> clientsReactor = asyncoreReactor.AsyncoreReactor()
>>> reactor = TestClientWrapper(clientsReactor.createClient(address))
>>> jsonAPI = JsonRpcClient(reactor)
>>> jsonAPI.connect()
>>> jsonAPI.callMethod("Host.ping", [], 1, 10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/yajsonrpc/client.py", line
39, in callMethod
resp = self._transport.recv(timeout=timeout)
File "/usr/share/vdsm/tests/jsonRpcUtils.py", line 100, in recv
return self._queue.get(timeout=timeout)[1]
File "/usr/lib64/python2.7/Queue.py", line 176, in get
raise Empty
Queue.Empty
Sheldon,
You and I resolved this problem but I will answer it here as well for the
benefit of everyone.
When using the Asyncore framework, there is a reactor on the server but also on
the client. Asyncore is multi-threaded and an event loop must be started for
the client reactor in order to process the server responses. See
tests/jsonRpcUtils.py:43 for the call to initialize the event loop thread in the
client reactor.
--
Adam Litke <agl(a)us.ibm.com>
IBM Linux Technology Center