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
e7697c16
Commit
e7697c16
authored
Feb 14, 2011
by
Antoine Millet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[bug#3961] New argument appeared to set a global call timeout.
parent
4c01cecf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
8 deletions
+16
-8
sjrpc/client/simple.py
sjrpc/client/simple.py
+5
-2
sjrpc/core/rpcconnection.py
sjrpc/core/rpcconnection.py
+11
-6
No files found.
sjrpc/client/simple.py
View file @
e7697c16
...
...
@@ -25,8 +25,8 @@ class SimpleRpcClient(ConnectionManager):
self
.
register
(
self
.
_connection
)
@
classmethod
def
from_addr
(
cls
,
addr
,
port
,
enable_ssl
=
False
,
cert
=
None
,
timeout
=
30.0
,
default_handler
=
None
,
on_disconnect
=
None
):
def
from_addr
(
cls
,
addr
,
port
,
enable_ssl
=
False
,
cert
=
None
,
timeout
=
None
,
conn_timeout
=
30.0
,
default_handler
=
None
,
on_disconnect
=
None
):
'''
Construct the instance of :class:`SimpleRpcClient` without providing
the :class:`RpcConnection` object. The :class:`RpcConnection` is
...
...
@@ -36,6 +36,8 @@ class SimpleRpcClient(ConnectionManager):
:param addr: the target ip address
:param port: the target port
:param ssl: enable SSL
:param timeout: the global call timeout setting
:param conn_timeout: the connection operation timeout
:param cert: is SSL is enabled, profile the filename of certificate to
check. If None, don't check certificate.
:param default_handler: the default handler to bind to the
...
...
@@ -45,6 +47,7 @@ class SimpleRpcClient(ConnectionManager):
'''
connection
=
RpcConnection
.
from_addr
(
addr
,
port
,
None
,
timeout
=
timeout
,
conn_timeout
=
conn_timeout
,
enable_ssl
=
enable_ssl
,
cert
=
cert
)
client
=
cls
(
connection
,
default_handler
=
default_handler
,
on_disconnect
=
on_disconnect
)
...
...
sjrpc/core/rpcconnection.py
View file @
e7697c16
...
...
@@ -29,7 +29,7 @@ class RpcConnection(object):
REQUEST_MESSAGE
=
{
'id'
:
None
,
'method'
:
None
,
'args'
:
[],
'kwargs'
:
{}}
RESPONSE_MESSAGE
=
{
'id'
:
None
,
'return'
:
None
,
'error'
:
None
}
def
__init__
(
self
,
sock
,
manager
,
handler
=
None
):
def
__init__
(
self
,
sock
,
manager
,
handler
=
None
,
timeout
=
None
):
# Sock of this connection:
self
.
_sock
=
sock
...
...
@@ -58,9 +58,12 @@ class RpcConnection(object):
# Is the RpcConnection connected to its peer:
self
.
_connected
=
True
# The global call timeout setting:
self
.
_call_timeout
=
timeout
@
classmethod
def
from_addr
(
cls
,
addr
,
port
,
manager
,
enable_ssl
=
False
,
timeout
=
30.0
,
cert
=
None
,
handler
=
None
):
def
from_addr
(
cls
,
addr
,
port
,
manager
,
enable_ssl
=
False
,
timeout
=
None
,
c
onn_timeout
=
30.0
,
c
ert
=
None
,
handler
=
None
):
'''
Construct the instance of :class:`RpcConnection` without providing
the :class:`socket` object. Socket is automatically created and passed
...
...
@@ -70,6 +73,8 @@ class RpcConnection(object):
:param port: the target port
:param manager: manager of this connection
:param enable_ssl: enable SSL
:param timeout: the global call timeout setting
:param conn_timeout: the connection operation timeout
:param cert: is SSL is enabled, profile the filename of certificate to
check. If None, don't check certificate.
:param handler: Handler to attach to this :class:`RpcConnection` object
...
...
@@ -81,10 +86,10 @@ class RpcConnection(object):
req
=
ssl
.
CERT_NONE
if
cert
is
None
else
ssl
.
CERT_REQUIRED
sock
=
ssl
.
wrap_socket
(
sock
,
certfile
=
None
,
cert_reqs
=
req
,
ssl_version
=
ssl
.
PROTOCOL_TLSv1
)
sock
.
settimeout
(
timeout
)
sock
.
settimeout
(
conn_
timeout
)
sock
.
connect
((
addr
,
port
))
sock
.
setblocking
(
False
)
return
cls
(
sock
,
manager
,
handler
)
return
cls
(
sock
,
manager
,
handler
,
timeout
=
timeout
)
def
__repr__
(
self
):
return
'<RpcConnection object>'
...
...
@@ -261,7 +266,7 @@ class RpcConnection(object):
timeout
=
kwargs
[
'_timeout'
]
del
kwargs
[
'_timeout'
]
else
:
timeout
=
None
timeout
=
self
.
_call_timeout
# Send the call to the peer:
msg_id
=
self
.
_send_call
(
method_name
,
*
args
,
**
kwargs
)
...
...
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