Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sjrpc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Mirror
sjrpc
Commits
4a764643
Commit
4a764643
authored
Jan 26, 2011
by
Antoine Millet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added timeout feature on (remote) call method.
parent
2daf7421
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
sjrpc/core/rpcconnection.py
sjrpc/core/rpcconnection.py
+12
-2
No files found.
sjrpc/core/rpcconnection.py
View file @
4a764643
...
...
@@ -211,7 +211,7 @@ class RpcConnection(object):
err
=
{
'exception'
:
error
,
'message'
:
message
}
self
.
_send_response
(
msg_id
,
error
=
err
)
def
call
(
self
,
method_name
,
*
args
,
**
kwargs
):
#TODO: timeout
def
call
(
self
,
method_name
,
*
args
,
**
kwargs
):
'''
Make a new remote call on the peer.
...
...
@@ -226,6 +226,12 @@ class RpcConnection(object):
seconds before to raise an :exc:`CallTimeout` exception if the peer
didnt respond.
'''
if
'_timeout'
in
kwargs
:
timeout
=
kwargs
[
'_timeout'
]
del
kwargs
[
'_timeout'
]
else
:
timeout
=
None
# Send the call to the peer:
msg_id
=
self
.
_send_call
(
method_name
,
*
args
,
**
kwargs
)
...
...
@@ -235,7 +241,11 @@ class RpcConnection(object):
'event'
:
threading
.
Event
()}
# Wait for the response:
self
.
_calls
[
msg_id
][
'event'
].
wait
()
self
.
_calls
[
msg_id
][
'event'
].
wait
(
timeout
)
# Check if timeout occured:
if
not
self
.
_calls
[
msg_id
][
'event'
].
is_set
():
raise
RpcError
(
'TimeoutError'
,
'remote method timeout'
)
# Check if error occured while execution:
if
self
.
_calls
[
msg_id
][
'error'
]
is
not
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment