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
e6545afa
Commit
e6545afa
authored
9 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
Task #8437: Use MethodTrigger from PyCommon
parent
2b0770bc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
MAC/Services/test/methodtrigger.py
+0
-68
0 additions, 68 deletions
MAC/Services/test/methodtrigger.py
MAC/Services/test/tPipelineStarter.py
+1
-1
1 addition, 1 deletion
MAC/Services/test/tPipelineStarter.py
with
1 addition
and
69 deletions
MAC/Services/test/methodtrigger.py
deleted
100644 → 0
+
0
−
68
View file @
2b0770bc
from
threading
import
Lock
,
Condition
__all__
=
[
"
MethodTrigger
"
]
class
MethodTrigger
:
"""
Set a flag when a specific method is called, possibly asynchronously. Caller can wait on this flag.
Example:
class Foo(object):
def bar(self):
pass
foo = Foo()
trigger = MethodTrigger(foo,
"
bar
"
)
if trigger.wait(): # Waits for 10 seconds for foo.bar() to get called
print
"
foo.bar() got called
"
else
# This will happen, as foo.bar() wasn
'
t called
print
"
foo.bar() did not get called
"
Calls that were made before the trigger has been installed will not get recorded.
"""
def
__init__
(
self
,
obj
,
method
):
assert
isinstance
(
obj
,
object
),
"
Object %s does not derive from object.
"
%
(
obj
,)
self
.
obj
=
obj
self
.
method
=
method
self
.
old_func
=
obj
.
__getattribute__
(
method
)
self
.
called
=
False
self
.
args
=
[]
self
.
kwargs
=
{}
self
.
lock
=
Lock
()
self
.
cond
=
Condition
(
self
.
lock
)
# Patch the target method
obj
.
__setattr__
(
method
,
self
.
trigger
)
def
trigger
(
self
,
*
args
,
**
kwargs
):
# Save the call parameters
self
.
args
=
args
self
.
kwargs
=
kwargs
# Call the original method
self
.
old_func
(
*
args
,
**
kwargs
)
# Restore the original method
self
.
obj
.
__setattr__
(
self
.
method
,
self
.
old_func
)
# Release waiting thread
with
self
.
lock
:
self
.
called
=
True
self
.
cond
.
notify
()
def
wait
(
self
,
timeout
=
10.0
):
# Wait for method to get called
with
self
.
lock
:
if
self
.
called
:
return
True
self
.
cond
.
wait
(
timeout
)
return
self
.
called
This diff is collapsed.
Click to expand it.
MAC/Services/test/tPipelineStarter.py
+
1
−
1
View file @
e6545afa
...
@@ -7,7 +7,7 @@ from lofar.mac.PipelineStarter import *
...
@@ -7,7 +7,7 @@ from lofar.mac.PipelineStarter import *
from
lofar.sas.otdb.OTDBBusListener
import
OTDBBusListener
from
lofar.sas.otdb.OTDBBusListener
import
OTDBBusListener
from
lofar.messaging
import
ToBus
,
Service
,
EventMessage
from
lofar.messaging
import
ToBus
,
Service
,
EventMessage
from
methodtrigger
import
MethodTrigger
from
lofar.common.
methodtrigger
import
MethodTrigger
import
subprocess
import
subprocess
import
unittest
import
unittest
...
...
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