Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ipaaca
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
ipaaca
Commits
408841b9
Commit
408841b9
authored
9 years ago
by
Ramin Yaghoubzadeh Torky
Browse files
Options
Downloads
Patches
Plain Diff
Py: OutputBuffer instances are tracked automatically in the lib
They are torn down on program exit (retracting all live IUs)
parent
cd980bed
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ipaacalib/python/src/ipaaca/buffer.py
+43
-2
43 additions, 2 deletions
ipaacalib/python/src/ipaaca/buffer.py
with
43 additions
and
2 deletions
ipaacalib/python/src/ipaaca/buffer.py
+
43
−
2
View file @
408841b9
...
...
@@ -37,6 +37,9 @@ import threading
import
uuid
import
traceback
import
weakref
import
atexit
import
rsb
import
ipaaca_pb2
...
...
@@ -54,6 +57,27 @@ __all__ = [
LOGGER
=
ipaaca
.
misc
.
get_library_logger
()
# set of objects to auto-clean on exit, assumes _teardown() method
TEARDOWN_OBJECTS
=
set
()
def
atexit_cleanup_function
():
'''
Function to call at program exit to auto-clean objects.
'''
global
TEARDOWN_OBJECTS
for
obj_r
in
TEARDOWN_OBJECTS
:
obj
=
obj_r
()
if
obj
is
not
None
:
# if weakref still valid
obj
.
_teardown
()
atexit
.
register
(
atexit_cleanup_function
)
def
auto_teardown_instances
(
fn
):
'''
Decorator function for object constructors, to add
new instances to the object set to auto-clean at exit.
'''
def
auto_teardown_instances_wrapper
(
instance
,
*
args
,
**
kwargs
):
global
TEARDOWN_OBJECTS
fn
(
instance
,
*
args
,
**
kwargs
)
TEARDOWN_OBJECTS
.
add
(
weakref
.
ref
(
instance
))
return
auto_teardown_instances_wrapper
class
IUStore
(
dict
):
"""
A dictionary storing IUs.
"""
def
__init__
(
self
):
...
...
@@ -207,7 +231,7 @@ class InputBuffer(Buffer):
self
.
_add_category_listener
(
str
(
self
.
_uuid
))
if
category_interests
is
not
None
:
self
.
add_category_interests
(
category_interests
)
def
_get_remote_server
(
self
,
iu
):
'''
Return (or create, store and return) a remote server.
'''
_owner
=
None
...
...
@@ -364,6 +388,7 @@ class OutputBuffer(Buffer):
"""
An OutputBuffer that holds local IUs.
"""
@auto_teardown_instances
def
__init__
(
self
,
owning_component_name
,
channel
=
None
,
participant_config
=
None
):
'''
Create an OutputBuffer.
...
...
@@ -382,6 +407,16 @@ class OutputBuffer(Buffer):
self
.
_id_prefix
=
str
(
owning_component_name
)
+
'
-
'
+
str
(
self
.
_uuid
)
+
'
-IU-
'
self
.
__iu_id_counter_lock
=
threading
.
Lock
()
def
_teardown
(
self
):
'''
OutputBuffer retracts remaining live IUs on teardown
'''
self
.
_retract_all_internal
()
def
__del__
(
self
):
'''
Perform teardown (IU retractions) as soon as Buffer is lost.
Note that at program exit the teardown might be called
twice for live objects (atexit, then del), but the
_retract_all_internal method prevents double retractions.
'''
self
.
_retract_all_internal
()
def
_remote_update_links
(
self
,
update
):
'''
Apply a remotely requested update to one of the stored IU
'
s links.
'''
if
update
.
uid
not
in
self
.
_iu_store
:
...
...
@@ -508,12 +543,18 @@ class OutputBuffer(Buffer):
def
_retract_iu
(
self
,
iu
):
'''
Retract an IU.
'''
iu
.
_retracted
=
True
iu_retraction
=
ipaaca_pb2
.
IURetraction
()
iu_retraction
.
uid
=
iu
.
uid
iu_retraction
.
revision
=
iu
.
revision
informer
=
self
.
_get_informer
(
iu
.
_category
)
informer
.
publishData
(
iu_retraction
)
iu
.
_retracted
=
True
def
_retract_all_internal
(
self
):
'''
Retract all IUs without removal (for Buffer teardown).
'''
for
iu
in
self
.
_iu_store
.
values
():
if
not
iu
.
_retracted
:
self
.
_retract_iu
(
iu
)
def
_send_iu_commission
(
self
,
iu
,
writer_name
):
'''
Send IU commission.
...
...
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