Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74899a7

Browse files
committed
Fix AttributeError on timeout with async
oc = zerorpc.Client(connect_to="tcp://127.0.0.1:8003") oc.test('whats up', async=True).wait() If there is a timeout: An exception is raised: "AttributeError: 'str' object has no attribute 'name'" Thanks jvangael for the bug report. This patch also add a test case.
1 parent 1573539 commit 74899a7

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

tests/test_client_async.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# -*- coding: utf-8 -*-
2+
# Open Source Initiative OSI - The MIT License (MIT):Licensing
3+
#
4+
# The MIT License (MIT)
5+
# Copyright (c) 2013 DotCloud Inc ([email protected])
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
# this software and associated documentation files (the "Software"), to deal in
9+
# the Software without restriction, including without limitation the rights to
10+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11+
# of the Software, and to permit persons to whom the Software is furnished to do
12+
# so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
26+
from nose.tools import assert_raises
27+
import gevent
28+
29+
from zerorpc import zmq
30+
import zerorpc
31+
from testutils import teardown, random_ipc_endpoint
32+
33+
34+
def test_client_server_client_timeout_with_async():
35+
endpoint = random_ipc_endpoint()
36+
37+
class MySrv(zerorpc.Server):
38+
39+
def lolita(self):
40+
return 42
41+
42+
def add(self, a, b):
43+
gevent.sleep(10)
44+
return a + b
45+
46+
srv = MySrv()
47+
srv.bind(endpoint)
48+
gevent.spawn(srv.run)
49+
50+
client = zerorpc.Client(timeout=2)
51+
client.connect(endpoint)
52+
53+
async_result = client.add(1, 4, async=True)
54+
with assert_raises(zerorpc.TimeoutExpired):
55+
print async_result.get()
56+
client.close()
57+
srv.close()
58+
59+
60+
def test_client_server_with_async():
61+
endpoint = random_ipc_endpoint()
62+
63+
class MySrv(zerorpc.Server):
64+
65+
def lolita(self):
66+
return 42
67+
68+
def add(self, a, b):
69+
return a + b
70+
71+
srv = MySrv()
72+
srv.bind(endpoint)
73+
gevent.spawn(srv.run)
74+
75+
client = zerorpc.Client()
76+
client.connect(endpoint)
77+
78+
async_result = client.lolita(async=True)
79+
assert async_result.get() == 42
80+
81+
async_result = client.add(1, 4, async=True)
82+
assert async_result.get() == 5

zerorpc/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def __call__(self, method, *args, **kargs):
241241
return self._process_response(request_event, bufchan, timeout)
242242

243243
async_result = gevent.event.AsyncResult()
244-
gevent.spawn(self._process_response, method, bufchan,
244+
gevent.spawn(self._process_response, request_event, bufchan,
245245
timeout).link(async_result)
246246
return async_result
247247
except:

0 commit comments

Comments
 (0)