Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
sjrpc
Commits
4a764643
Commit
4a764643
authored
14 years ago
by
Antoine Millet
Browse files
Options
Downloads
Patches
Plain Diff
Added timeout feature on (remote) call method.
parent
2daf7421
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sjrpc/core/rpcconnection.py
+12
-2
12 additions, 2 deletions
sjrpc/core/rpcconnection.py
with
12 additions
and
2 deletions
sjrpc/core/rpcconnection.py
+
12
−
2
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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment