Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
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
RadioObservatory
LOFAR
Commits
a557f0d3
Commit
a557f0d3
authored
9 years ago
by
Jan Rinze Peterzon
Browse files
Options
Downloads
Patches
Plain Diff
Task #8531: brush up messaging python code to adhere to style guide.
parent
b5547e8e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
LCS/Messaging/python/messaging/RPC.py
+32
-34
32 additions, 34 deletions
LCS/Messaging/python/messaging/RPC.py
LCS/Messaging/python/messaging/Service.py
+2
-2
2 additions, 2 deletions
LCS/Messaging/python/messaging/Service.py
with
34 additions
and
36 deletions
LCS/Messaging/python/messaging/RPC.py
+
32
−
34
View file @
a557f0d3
...
@@ -41,11 +41,11 @@ class RPC():
...
@@ -41,11 +41,11 @@ class RPC():
As a side-effect the sender and session are destroyed.
As a side-effect the sender and session are destroyed.
"""
"""
def
__init__
(
self
,
service
,
**
kwargs
):
#busname=None, timeout=None, ForwardExceptions=None, Verbose=None):
def
__init__
(
self
,
service
,
**
kwargs
):
"""
"""
Initialize an Remote procedure call using:
Initialize an Remote procedure call using:
service= <str> Service Name
service= <str> Service Name
bus
=
<str> Bus Name
bus
name=
<str> Bus Name
timeout= <float> Time to wait in seconds before the call is considered a failure.
timeout= <float> Time to wait in seconds before the call is considered a failure.
Verbose= <bool> If True output extra logging to stdout.
Verbose= <bool> If True output extra logging to stdout.
...
@@ -60,9 +60,9 @@ class RPC():
...
@@ -60,9 +60,9 @@ class RPC():
if
self
.
BusName
is
None
:
if
self
.
BusName
is
None
:
self
.
Request
=
ToBus
(
self
.
ServiceName
)
self
.
Request
=
ToBus
(
self
.
ServiceName
)
else
:
else
:
self
.
Request
=
ToBus
(
self
.
BusName
+
"
/
"
+
self
.
ServiceName
)
self
.
Request
=
ToBus
(
"
%s/%s
"
%
(
self
.
BusName
,
self
.
ServiceName
)
)
if
len
(
kwargs
):
if
len
(
kwargs
):
raise
AttributeError
(
"
Unexpected argument passed to RPC class: %s
"
,
kwargs
)
raise
AttributeError
(
"
Unexpected argument passed to RPC class: %s
"
%
(
kwargs
)
)
def
__enter__
(
self
):
def
__enter__
(
self
):
"""
"""
...
@@ -88,17 +88,15 @@ class RPC():
...
@@ -88,17 +88,15 @@ class RPC():
"""
"""
timeout
=
kwargs
.
pop
(
"
timeout
"
,
self
.
timeout
)
timeout
=
kwargs
.
pop
(
"
timeout
"
,
self
.
timeout
)
Content
=
args_as_content
(
*
args
,
**
kwargs
)
Content
=
args_as_content
(
*
args
,
**
kwargs
)
HasArgs
,
HasKwArgs
=
analyze_args
(
args
,
kwargs
)
HasArgs
,
HasKwArgs
=
analyze_args
(
args
,
kwargs
)
# create unique reply address for this rpc call
# create unique reply address for this rpc call
options
=
{
'
create
'
:
'
always
'
,
'
delete
'
:
'
receiver
'
}
options
=
{
'
create
'
:
'
always
'
,
'
delete
'
:
'
receiver
'
}
ReplyAddress
=
"
reply.
"
+
str
(
uuid
.
uuid4
())
ReplyAddress
=
"
reply.
%s
"
%
(
str
(
uuid
.
uuid4
())
)
if
self
.
BusName
is
None
:
if
self
.
BusName
is
None
:
Reply
=
FromBus
(
ReplyAddress
+
"
;
"
+
str
(
options
))
Reply
=
FromBus
(
"
%s ; %s
"
%
(
ReplyAddress
,
str
(
options
))
)
else
:
else
:
Reply
=
FromBus
(
self
.
BusName
+
"
/
"
+
ReplyAddress
)
Reply
=
FromBus
(
"
%s/%s
"
%
(
self
.
BusName
,
ReplyAddress
)
)
with
Reply
:
with
Reply
:
MyMsg
=
RequestMessage
(
Content
,
ReplyAddress
,
has_args
=
HasArgs
,
has_kwargs
=
HasKwArgs
)
MyMsg
=
RequestMessage
(
Content
,
ReplyAddress
,
has_args
=
HasArgs
,
has_kwargs
=
HasKwArgs
)
MyMsg
.
ttl
=
timeout
MyMsg
.
ttl
=
timeout
...
@@ -117,7 +115,7 @@ class RPC():
...
@@ -117,7 +115,7 @@ class RPC():
if
isinstance
(
answer
,
ReplyMessage
)
is
False
:
if
isinstance
(
answer
,
ReplyMessage
)
is
False
:
# if we come here we had a Time-Out
# if we come here we had a Time-Out
status
[
"
state
"
]
=
"
ERROR
"
status
[
"
state
"
]
=
"
ERROR
"
status
[
"
errmsg
"
]
=
"
Incorrect messagetype (
"
+
str
(
type
(
answer
))
+
"
) received.
"
status
[
"
errmsg
"
]
=
"
Incorrect messagetype (
%s) received.
"
%
(
str
(
type
(
answer
))
)
status
[
"
backtrace
"
]
=
""
status
[
"
backtrace
"
]
=
""
raise
RPCException
(
status
)
raise
RPCException
(
status
)
...
...
This diff is collapsed.
Click to expand it.
LCS/Messaging/python/messaging/Service.py
+
2
−
2
View file @
a557f0d3
...
@@ -62,7 +62,7 @@ class MessageHandlerInterface(object):
...
@@ -62,7 +62,7 @@ class MessageHandlerInterface(object):
def
handle_message
(
self
,
msg
):
def
handle_message
(
self
,
msg
):
"
Function the should handle the received message and return a result.
"
"
Function the should handle the received message and return a result.
"
raise
Exception
(
"
OOPS! YOU ENDED UP IN THE MESSAGE HANDLER OF THE ABSTRACT BASE CLASS!
"
)
raise
NotImplementedError
(
"
OOPS! YOU ENDED UP IN THE MESSAGE HANDLER OF THE ABSTRACT BASE CLASS!
"
)
def
finalize_handling
(
self
,
successful
):
def
finalize_handling
(
self
,
successful
):
"
Called in the main loop after the result was send back to the requester.
"
"
Called in the main loop after the result was send back to the requester.
"
...
@@ -250,7 +250,7 @@ class Service(object):
...
@@ -250,7 +250,7 @@ class Service(object):
reply_msg
.
backtrace
=
backtrace
reply_msg
.
backtrace
=
backtrace
# show the message content if required by the verbose flag.
# show the message content if required by the verbose flag.
if
self
.
verbose
is
True
:
if
self
.
verbose
==
True
:
reply_msg
.
show
()
reply_msg
.
show
()
# send the result to the RPC client
# send the result to the RPC client
...
...
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