eventdispatch 0.1.11__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eventdispatch/__init__.py +0 -0
- eventdispatch/aux1.py +260 -0
- eventdispatch/core.py +197 -0
- eventdispatch/example1.py +287 -0
- eventdispatch-0.1.11.dist-info/LICENSE +202 -0
- eventdispatch-0.1.11.dist-info/METADATA +237 -0
- eventdispatch-0.1.11.dist-info/RECORD +10 -0
- eventdispatch-0.1.11.dist-info/WHEEL +5 -0
- eventdispatch-0.1.11.dist-info/entry_points.txt +2 -0
- eventdispatch-0.1.11.dist-info/top_level.txt +1 -0
File without changes
|
eventdispatch/aux1.py
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
'''
|
2
|
+
Created on 2025-05-23
|
3
|
+
|
4
|
+
@author: Charlie Yan
|
5
|
+
|
6
|
+
Copyright (c) 2025, Charlie Yan
|
7
|
+
License: Apache-2.0 (see LICENSE for details)
|
8
|
+
'''
|
9
|
+
from core import *
|
10
|
+
|
11
|
+
def python2_makedirs_wrapper(path):
|
12
|
+
try:
|
13
|
+
os.makedirs(path)
|
14
|
+
except OSError as e:
|
15
|
+
if e.errno != errno.EEXIST:
|
16
|
+
raise
|
17
|
+
|
18
|
+
def python3_makedirs_wrapper(path):
|
19
|
+
os.makedirs(
|
20
|
+
path,
|
21
|
+
exist_ok=True)
|
22
|
+
|
23
|
+
PYTHON2 = False
|
24
|
+
makedirs_wrapper = python3_makedirs_wrapper
|
25
|
+
if sys.version_info.major == 2:
|
26
|
+
PYTHON2 = True
|
27
|
+
import errno
|
28
|
+
makedirs_wrapper = python2_makedirs_wrapper
|
29
|
+
|
30
|
+
class bcolors:
|
31
|
+
# https://godoc.org/github.com/whitedevops/colors
|
32
|
+
DEFAULT = "\033[39m"
|
33
|
+
BLACK = "\033[30m"
|
34
|
+
RED = "\033[31m"
|
35
|
+
GREEN = "\033[32m"
|
36
|
+
YELLOW = "\033[33m"
|
37
|
+
BLUE = "\033[34m"
|
38
|
+
MAGENTA = "\033[35m"
|
39
|
+
CYAN = "\033[36m"
|
40
|
+
LGRAY = "\033[37m"
|
41
|
+
DARKGRAY = "\033[90m"
|
42
|
+
FAIL = "\033[91m"
|
43
|
+
OKGREEN = '\033[92m'
|
44
|
+
WARNING = '\033[93m'
|
45
|
+
OKBLUE = '\033[94m'
|
46
|
+
HEADER = '\033[95m'
|
47
|
+
LIGHTCYAN = '\033[96m'
|
48
|
+
WHITE = "\033[97m"
|
49
|
+
|
50
|
+
ENDC = '\033[0m'
|
51
|
+
BOLD = '\033[1m'
|
52
|
+
DIM = "\033[2m"
|
53
|
+
UNDERLINE = '\033[4m'
|
54
|
+
BLINK = "\033[5m"
|
55
|
+
REVERSE = "\033[7m"
|
56
|
+
HIDDEN = "\033[8m"
|
57
|
+
|
58
|
+
BG_DEFAULT = "\033[49m"
|
59
|
+
BG_BLACK = "\033[40m"
|
60
|
+
BG_RED = "\033[41m"
|
61
|
+
BG_GREEN = "\033[42m"
|
62
|
+
BG_YELLOW = "\033[43m"
|
63
|
+
BG_BLUE = "\033[44m"
|
64
|
+
BG_MAGENTA = "\033[45m"
|
65
|
+
BG_CYAN = "\033[46m"
|
66
|
+
BG_GRAY = "\033[47m"
|
67
|
+
BG_DKGRAY = "\033[100m"
|
68
|
+
BG_LRED = "\033[101m"
|
69
|
+
BG_LGREEN = "\033[102m"
|
70
|
+
BG_LYELLOW = "\033[103m"
|
71
|
+
BG_LBLUE = "\033[104m"
|
72
|
+
BG_LMAGENTA = "\033[105m"
|
73
|
+
BG_LCYAN = "\033[106m"
|
74
|
+
BG_WHITE = "\033[107m"
|
75
|
+
|
76
|
+
def nonempty_queue_exists(
|
77
|
+
blackboard,
|
78
|
+
admissible_nonempty_keys,
|
79
|
+
verbose = False):
|
80
|
+
for k in blackboard.keys():
|
81
|
+
if k[-6:] == "_queue":
|
82
|
+
mutex_k = k[:-6] + "_mutex"
|
83
|
+
blackboard[mutex_k].acquire()
|
84
|
+
queue_size = len(blackboard[k])
|
85
|
+
blackboard[mutex_k].release()
|
86
|
+
if verbose:
|
87
|
+
print("%s queue_size %d" % (k, queue_size))
|
88
|
+
print(blackboard[k])
|
89
|
+
|
90
|
+
if queue_size > 0:
|
91
|
+
if verbose:
|
92
|
+
print("nonempty k: ", k, queue_size)
|
93
|
+
if k not in admissible_nonempty_keys:
|
94
|
+
return True
|
95
|
+
return False
|
96
|
+
|
97
|
+
def wrap_with_prints(pre_msg, post_msg):
|
98
|
+
'''useful for for example printing with color'''
|
99
|
+
def decorator(func):
|
100
|
+
def wrapper(*args, **kwargs):
|
101
|
+
print(pre_msg, end="")
|
102
|
+
res = func(*args, **kwargs)
|
103
|
+
print(post_msg, end="")
|
104
|
+
return res
|
105
|
+
return wrapper
|
106
|
+
return decorator
|
107
|
+
|
108
|
+
class CommonEvent(Event):
|
109
|
+
debug_color = bcolors.LIGHTCYAN
|
110
|
+
|
111
|
+
def __init__(self, event_id, *args, **kwargs):
|
112
|
+
super(CommonEvent, self).__init__(
|
113
|
+
event_id, *args, **kwargs)
|
114
|
+
self._exception = False
|
115
|
+
self.blackboard = args[0]
|
116
|
+
self.instance = ""
|
117
|
+
|
118
|
+
wrap_instance_method(self, 'log',
|
119
|
+
wrap_with_prints(self.debug_color, bcolors.ENDC))
|
120
|
+
|
121
|
+
def log(self, *args):
|
122
|
+
print(*args)
|
123
|
+
|
124
|
+
@staticmethod
|
125
|
+
def deserialize(ed, blackboard, *args, **kwargs):
|
126
|
+
tokens = args[0]
|
127
|
+
# ed.log("TOKENS! {}".format(tokens))
|
128
|
+
if len(tokens) < 1:
|
129
|
+
raise Exception("not enough tokens", len(tokens))
|
130
|
+
|
131
|
+
return (ed.reserve_event_id(), blackboard), tuple(tokens)
|
132
|
+
|
133
|
+
class BlackboardQueueCVED(EventDispatch):
|
134
|
+
def __init__(self, blackboard, name):
|
135
|
+
super(BlackboardQueueCVED, self).__init__(
|
136
|
+
blackboard, name + "_dispatch")
|
137
|
+
|
138
|
+
self.register_blackboard_assets(
|
139
|
+
blackboard, name)
|
140
|
+
|
141
|
+
self.event_id_max = 0
|
142
|
+
|
143
|
+
def prior_cb(self, blackboard):
|
144
|
+
pass
|
145
|
+
|
146
|
+
def post_cb(self, blackboard):
|
147
|
+
self.log("post_cb!!! {}".format(len(blackboard[self.queue_name])))
|
148
|
+
|
149
|
+
def register_blackboard_assets(self, blackboard, name):
|
150
|
+
self.name = name
|
151
|
+
|
152
|
+
self.hb_key = name + "_hb"
|
153
|
+
if self.hb_key not in blackboard:
|
154
|
+
blackboard[self.hb_key] = True
|
155
|
+
# assert(self.hb_key in blackboard)
|
156
|
+
|
157
|
+
self.mutex_name = name + "_mutex"
|
158
|
+
if self.mutex_name not in blackboard:
|
159
|
+
# without creating one explicitly
|
160
|
+
# condition has underlying mutex
|
161
|
+
blackboard[self.mutex_name] = Lock()
|
162
|
+
# assert(self.mutex_name in blackboard)
|
163
|
+
|
164
|
+
self.cv_name = name + "_cv"
|
165
|
+
if self.cv_name not in blackboard:
|
166
|
+
blackboard[self.cv_name] = Condition(
|
167
|
+
blackboard[self.mutex_name])
|
168
|
+
# assert(self.cv_name in blackboard)
|
169
|
+
|
170
|
+
self.queue_name = name + "_queue"
|
171
|
+
if self.queue_name not in blackboard:
|
172
|
+
blackboard[self.queue_name] = []
|
173
|
+
# assert(self.queue_name in blackboard)
|
174
|
+
|
175
|
+
def log(self, msg, params = None):
|
176
|
+
print(msg)
|
177
|
+
|
178
|
+
def reserve_event_id(self):
|
179
|
+
x = self.event_id_max
|
180
|
+
self.event_id_max = (self.event_id_max + 1) % (30000)
|
181
|
+
return x
|
182
|
+
|
183
|
+
def release_event_id(self, event_id):
|
184
|
+
pass
|
185
|
+
|
186
|
+
def run(self, blackboard, # expected, dict
|
187
|
+
prefix, # expected, str
|
188
|
+
empty_cv_name = None, # expected, str
|
189
|
+
debug_color = None):
|
190
|
+
assert(blackboard is not None)
|
191
|
+
|
192
|
+
if (debug_color is not None):
|
193
|
+
wrap_instance_method(self, 'log',
|
194
|
+
wrap_with_prints(debug_color, bcolors.ENDC))
|
195
|
+
# [example] decorator
|
196
|
+
|
197
|
+
while(blackboard[self.hb_key]):
|
198
|
+
blackboard[self.mutex_name].acquire()
|
199
|
+
# syntax in while bool expression (cv predicate) is key
|
200
|
+
while blackboard[self.hb_key] and (
|
201
|
+
len(blackboard[self.queue_name]) == 0):
|
202
|
+
blackboard[self.cv_name].wait()
|
203
|
+
# Wait until notified or until a timeout occurs.
|
204
|
+
# If the calling thread has not acquired the lock
|
205
|
+
# when this method is called,
|
206
|
+
# a RuntimeError is raised.
|
207
|
+
# add conditions (predicates) to protect
|
208
|
+
# against spurious wakeups prior or after
|
209
|
+
# condition is actually met
|
210
|
+
blackboard[self.mutex_name].release()
|
211
|
+
|
212
|
+
# could be woken from shutdown procedure
|
213
|
+
if len(blackboard[self.queue_name]) == 0:
|
214
|
+
self.log("woken from shutdown")
|
215
|
+
break
|
216
|
+
|
217
|
+
# for now, expose this so other types can override it
|
218
|
+
# so we don't need to re-write the whole thing
|
219
|
+
self.prior_cb(blackboard)
|
220
|
+
|
221
|
+
##### core ED logic ####################################
|
222
|
+
while len(blackboard[self.queue_name]) > 0: # buffer and [drain]
|
223
|
+
serialized_class_args = blackboard[self.queue_name].pop(0)
|
224
|
+
|
225
|
+
# s (serialized_event) expected to be
|
226
|
+
# array of [<class>, args]
|
227
|
+
if len(serialized_class_args) == 0:
|
228
|
+
continue
|
229
|
+
|
230
|
+
# deserialize & dispatch
|
231
|
+
try:
|
232
|
+
constructor_args, dispatch_args = blackboard[
|
233
|
+
serialized_class_args[0]].deserialize(
|
234
|
+
self,
|
235
|
+
blackboard,
|
236
|
+
serialized_class_args[1:])
|
237
|
+
# mechanism
|
238
|
+
self.dispatch(
|
239
|
+
blackboard[serialized_class_args[0]](
|
240
|
+
*constructor_args),
|
241
|
+
*dispatch_args)
|
242
|
+
except Exception as e:
|
243
|
+
self.log(self.ed_id
|
244
|
+
+ " failed dispatch %s, exception %s" % (
|
245
|
+
str(serialized_class_args), str(e)))
|
246
|
+
########################################################
|
247
|
+
|
248
|
+
self.post_cb(blackboard)
|
249
|
+
|
250
|
+
# ED tries to 'cleanup'
|
251
|
+
if empty_cv_name is not None:
|
252
|
+
if len(blackboard[self.queue_name]) == 0 and\
|
253
|
+
empty_cv_name in blackboard:
|
254
|
+
self.log("notifying " + empty_cv_name)
|
255
|
+
blackboard[empty_cv_name].acquire()
|
256
|
+
blackboard[empty_cv_name].notify_all()
|
257
|
+
blackboard[empty_cv_name].release()
|
258
|
+
|
259
|
+
self.log(self.name + " shutdown")
|
260
|
+
|
eventdispatch/core.py
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
'''
|
2
|
+
Created on 2025-05-23
|
3
|
+
|
4
|
+
@author: Charlie Yan
|
5
|
+
|
6
|
+
Copyright (c) 2025, Charlie Yan
|
7
|
+
License: Apache-2.0 (see LICENSE for details)
|
8
|
+
'''
|
9
|
+
from __future__ import print_function
|
10
|
+
|
11
|
+
import sys, time
|
12
|
+
|
13
|
+
import threading, collections
|
14
|
+
from threading import Condition, Lock, Thread
|
15
|
+
|
16
|
+
def wrap_instance_method(instance, method_name, wrapper_with_args):
|
17
|
+
wrapped_method = wrapper_with_args(getattr(instance, method_name))
|
18
|
+
setattr(instance, method_name, wrapped_method)
|
19
|
+
|
20
|
+
def call_when_switch_turned_on(obj, switch, switch_lock):
|
21
|
+
def decorator(func): # func should return void
|
22
|
+
def wrapper(*args, **kwargs):
|
23
|
+
lock_obj = getattr(obj, switch_lock)
|
24
|
+
lock_obj.acquire() # optionally, non-blocking acquire
|
25
|
+
switch_state = getattr(obj, switch)
|
26
|
+
if (not switch_state): # tells you lock state @ this call, it may be released immediately after
|
27
|
+
lock_obj.release() # 2019-01-09 SUPER #IMPORTANT
|
28
|
+
raise Exception("call_when_switch_turned_on: off, doing nothing")
|
29
|
+
res = func(*args, **kwargs)
|
30
|
+
lock_obj.release()
|
31
|
+
return res
|
32
|
+
return wrapper
|
33
|
+
return decorator
|
34
|
+
|
35
|
+
class Blackboard(dict):
|
36
|
+
def __init__(self, *args, **kwargs):
|
37
|
+
self.mutex = Lock()
|
38
|
+
self.update(dict(*args, **kwargs)) # use the free update to set keys
|
39
|
+
|
40
|
+
def __setitem__(self, key, value):
|
41
|
+
with self.mutex:
|
42
|
+
super(Blackboard, self).__setitem__(key, value)
|
43
|
+
|
44
|
+
def __getitem__(self, key):
|
45
|
+
with self.mutex:
|
46
|
+
res = super().__getitem__(key)
|
47
|
+
return res
|
48
|
+
|
49
|
+
def __delitem__(self, key):
|
50
|
+
with self.mutex:
|
51
|
+
super().__delitem__(key)
|
52
|
+
|
53
|
+
class EventThread(threading.Thread):
|
54
|
+
"""
|
55
|
+
a thread, with callback, oneshot, delay, terminate additions
|
56
|
+
"""
|
57
|
+
def __init__(self,
|
58
|
+
callback = None,
|
59
|
+
oneshot = True,
|
60
|
+
delay_secs = None,
|
61
|
+
*args, **kwargs):
|
62
|
+
super(EventThread, self).__init__(*args, **kwargs)
|
63
|
+
self.callback = callback
|
64
|
+
self.oneshot = oneshot
|
65
|
+
self.delay_secs = delay_secs
|
66
|
+
|
67
|
+
# IMPORTANT, threading library
|
68
|
+
# wants to call a function _stop()
|
69
|
+
# so we must name this to not override that
|
70
|
+
self._stop_event = threading.Event()
|
71
|
+
|
72
|
+
def terminate(self):
|
73
|
+
self._stop_event.set()
|
74
|
+
|
75
|
+
def stopped(self):
|
76
|
+
return self._stop_event.isSet()
|
77
|
+
|
78
|
+
def run(self):
|
79
|
+
# print "starting up stoppable thread"
|
80
|
+
if self.delay_secs is not None:
|
81
|
+
time.sleep(self.delay_secs)
|
82
|
+
super(EventThread, self).run()
|
83
|
+
if self.oneshot:
|
84
|
+
self.terminate()
|
85
|
+
if self.callback:
|
86
|
+
self.callback()
|
87
|
+
|
88
|
+
class Event(object):
|
89
|
+
'''
|
90
|
+
an interface / abstract-base-class
|
91
|
+
child classes must override deserialize, dispatch, and finish
|
92
|
+
'''
|
93
|
+
def __init__(self, event_id, *args, **kwargs):
|
94
|
+
self.event_id = event_id
|
95
|
+
# note: on construction, does NOT have/need a blackboard
|
96
|
+
# when dispatched, it MAY have a blackboard (access to actors)
|
97
|
+
self.blackboard = None
|
98
|
+
|
99
|
+
# note: on construction, does NOT have/need an ED
|
100
|
+
# when dispatched, it MUST have an ED (access to dispatch, events)
|
101
|
+
self.event_dispatch = None
|
102
|
+
# not fixed, can be changed across different dispatches
|
103
|
+
|
104
|
+
# methods for the child to override
|
105
|
+
def get_id(self):
|
106
|
+
# return self.__class__.__name__ + "@" + str(self.event_id)
|
107
|
+
return self.event_id
|
108
|
+
|
109
|
+
@staticmethod
|
110
|
+
def deserialize(ed, blackboard, *args, **kwargs):
|
111
|
+
# up to the Event class to define
|
112
|
+
# returns 2 tuples, constructor_args, dispatch_args
|
113
|
+
# unlike dispatch / finish, involves no instance
|
114
|
+
raise NotImplementedError
|
115
|
+
|
116
|
+
def dispatch(self, event_dispatch, *args, **kwargs):
|
117
|
+
# CAN EITHER PASS IN ARGS OR KWARGS HERE
|
118
|
+
# OR SET THEM IN CONSTRUCTOR
|
119
|
+
# OR SET THEM IN THE BLACKBOARD
|
120
|
+
# unlike deserialize / finish, happens in its own thread
|
121
|
+
raise NotImplementedError
|
122
|
+
|
123
|
+
def finish(self, event_dispatch, *args, **kwargs):
|
124
|
+
# unlike deserialize / dispatch, involves other events
|
125
|
+
|
126
|
+
# BEST PRACTICE:
|
127
|
+
# you should deal with OUTCOMES here
|
128
|
+
# do risky / uncertain stuff inside dispatch
|
129
|
+
# and deal with the outcomes here
|
130
|
+
raise NotImplementedError
|
131
|
+
|
132
|
+
class EventDispatch(object):
|
133
|
+
def __init__(self, blackboard = None, ed_id = None):
|
134
|
+
self.thread_registry = {}
|
135
|
+
self.mutex_registry = {}
|
136
|
+
|
137
|
+
self.event_id_pool = set()
|
138
|
+
self.event_id_pool_all = set()
|
139
|
+
|
140
|
+
self.dispatch_mutex = threading.Lock()
|
141
|
+
self.dispatch_switch_mutex = threading.Lock()
|
142
|
+
self.dispatch_switch = True
|
143
|
+
|
144
|
+
wrap_instance_method(self, 'dispatch',
|
145
|
+
call_when_switch_turned_on(
|
146
|
+
self, "dispatch_switch",
|
147
|
+
"dispatch_switch_mutex")) # [example] decorator
|
148
|
+
# safety mechanism:
|
149
|
+
# if any event sets the switch off
|
150
|
+
# no other events are dispatched
|
151
|
+
# until the switch is cleared
|
152
|
+
|
153
|
+
if (blackboard is not None and ed_id is not None):
|
154
|
+
# give an ED a blackboard on which other EDs live
|
155
|
+
# for when there is no ROS infrastructure for example
|
156
|
+
self.blackboard = blackboard
|
157
|
+
self.ed_id = ed_id
|
158
|
+
self.blackboard[ed_id] = self # register self on blackboard
|
159
|
+
|
160
|
+
# something child ED class can override
|
161
|
+
# for Event.deserialize to form some event_id
|
162
|
+
def reserve_event_id(self):
|
163
|
+
if len(self.event_id_pool) > 0:
|
164
|
+
return self.event_id_pool.pop()
|
165
|
+
else:
|
166
|
+
new_id = len(self.event_id_pool_all)
|
167
|
+
self.event_id_pool_all.add(new_id)
|
168
|
+
return new_id
|
169
|
+
|
170
|
+
def release_event_id(self, event_id):
|
171
|
+
# return event_id to pool
|
172
|
+
self.event_id_pool.add(event_id)
|
173
|
+
|
174
|
+
def dispatch(self, event, *args, **kwargs):
|
175
|
+
with self.dispatch_mutex:
|
176
|
+
# print("dispatching %s" % (event.get_id())) # debug
|
177
|
+
self.thread_registry[event.get_id()] = EventThread(
|
178
|
+
target=lambda args = args, kwargs = kwargs:\
|
179
|
+
event.dispatch(self, *args, **kwargs),
|
180
|
+
# note that the event is dispatched with a reference
|
181
|
+
# to the event dispatch, giving access / control
|
182
|
+
# over other events
|
183
|
+
callback=lambda event = event, args = args, kwargs = kwargs:\
|
184
|
+
self.dispatch_finish(event, *args, **kwargs))
|
185
|
+
self.thread_registry[event.get_id()].start()
|
186
|
+
|
187
|
+
def dispatch_finish(self, event, *args, **kwargs):
|
188
|
+
with self.dispatch_mutex:
|
189
|
+
event_id = event.get_id()
|
190
|
+
self.thread_registry.pop(event_id, None)
|
191
|
+
|
192
|
+
# self.log("finishing %s" % (event.get_id())) # debug
|
193
|
+
event.finish(self, *args, **kwargs)
|
194
|
+
# ONLY the event defines what is dispatched next
|
195
|
+
# this includes multiple subsequent concurrent events
|
196
|
+
|
197
|
+
self.release_event_id(event_id)
|
@@ -0,0 +1,287 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
'''
|
3
|
+
Created on 2025-05-23
|
4
|
+
|
5
|
+
@author: Charlie Yan
|
6
|
+
|
7
|
+
Copyright (c) 2025, Charlie Yan
|
8
|
+
License: Apache-2.0 (see LICENSE for details)
|
9
|
+
'''
|
10
|
+
|
11
|
+
from core import *
|
12
|
+
from aux1 import *
|
13
|
+
|
14
|
+
import signal, time, os, sys, random, threading
|
15
|
+
|
16
|
+
# these are examples Event classes
|
17
|
+
# together, they define the drift and control in a system
|
18
|
+
# defined here, they are registered as key-value paris in the Blackboard instance below
|
19
|
+
|
20
|
+
class WorkItemEvent(CommonEvent):
|
21
|
+
debug_color = bcolors.WARNING
|
22
|
+
|
23
|
+
def dispatch(self, event_dispatch, *args, **kwargs):
|
24
|
+
self.log("WorkItemEvent: {} remaining items".format(args[0]))
|
25
|
+
|
26
|
+
self.blackboard[event_dispatch.cv_name].acquire()
|
27
|
+
self.blackboard[event_dispatch.queue_name].extend([
|
28
|
+
[
|
29
|
+
"UncertaintEvent1",
|
30
|
+
args[0]-1
|
31
|
+
],
|
32
|
+
[
|
33
|
+
"UncertaintEvent2",
|
34
|
+
args[0]-1
|
35
|
+
]
|
36
|
+
])
|
37
|
+
self.blackboard[event_dispatch.cv_name].notify(1)
|
38
|
+
self.blackboard[event_dispatch.cv_name].release()
|
39
|
+
|
40
|
+
def finish(self, event_dispatch, *args, **kwargs):
|
41
|
+
self.log("finish!", args, kwargs)
|
42
|
+
|
43
|
+
class UncertaintEvent1(CommonEvent):
|
44
|
+
debug_color = bcolors.CYAN
|
45
|
+
|
46
|
+
def dispatch(self, event_dispatch, *args, **kwargs):
|
47
|
+
self.log("dispatch!", args, kwargs)
|
48
|
+
|
49
|
+
time.sleep(random.randint(1, 5))
|
50
|
+
|
51
|
+
with self.blackboard["result_mutex"]:
|
52
|
+
self.blackboard["result1"] = random.randint(1, 5)
|
53
|
+
|
54
|
+
def finish(self, event_dispatch, *args, **kwargs):
|
55
|
+
self.log("finish!", args, kwargs)
|
56
|
+
|
57
|
+
with self.blackboard["result_mutex"]:
|
58
|
+
if self.blackboard["result2"] > 0:
|
59
|
+
self.log("UncertaintEvent2 wins")
|
60
|
+
|
61
|
+
s = self.blackboard["result1"] + self.blackboard["result2"]
|
62
|
+
self.blackboard["result1"] = 0
|
63
|
+
self.blackboard["result2"] = 0
|
64
|
+
|
65
|
+
self.blackboard[event_dispatch.cv_name].acquire()
|
66
|
+
self.blackboard[event_dispatch.queue_name].extend([
|
67
|
+
[
|
68
|
+
"CheckEvent1",
|
69
|
+
args[0],
|
70
|
+
s
|
71
|
+
],
|
72
|
+
])
|
73
|
+
self.blackboard[event_dispatch.cv_name].notify(1)
|
74
|
+
self.blackboard[event_dispatch.cv_name].release()
|
75
|
+
|
76
|
+
class UncertaintEvent2(CommonEvent):
|
77
|
+
debug_color = bcolors.MAGENTA
|
78
|
+
|
79
|
+
def dispatch(self, event_dispatch, *args, **kwargs):
|
80
|
+
self.log("dispatch!", args, kwargs)
|
81
|
+
|
82
|
+
time.sleep(random.randint(1, 10))
|
83
|
+
|
84
|
+
with self.blackboard["result_mutex"]:
|
85
|
+
self.blackboard["result2"] = random.randint(1, 10)
|
86
|
+
|
87
|
+
def finish(self, event_dispatch, *args, **kwargs):
|
88
|
+
self.log("finish!", args, kwargs)
|
89
|
+
|
90
|
+
with self.blackboard["result_mutex"]:
|
91
|
+
if self.blackboard["result1"] > 0:
|
92
|
+
self.log("UncertaintEvent1 wins")
|
93
|
+
|
94
|
+
s = self.blackboard["result1"] + self.blackboard["result2"]
|
95
|
+
self.blackboard["result1"] = 0
|
96
|
+
self.blackboard["result2"] = 0
|
97
|
+
|
98
|
+
self.blackboard[event_dispatch.cv_name].acquire()
|
99
|
+
self.blackboard[event_dispatch.queue_name].extend([
|
100
|
+
[
|
101
|
+
"CheckEvent1",
|
102
|
+
args[0],
|
103
|
+
s
|
104
|
+
],
|
105
|
+
])
|
106
|
+
self.blackboard[event_dispatch.cv_name].notify(1)
|
107
|
+
self.blackboard[event_dispatch.cv_name].release()
|
108
|
+
|
109
|
+
class CheckEvent1(CommonEvent):
|
110
|
+
debug_color = bcolors.RED
|
111
|
+
|
112
|
+
def dispatch(self, event_dispatch, *args, **kwargs):
|
113
|
+
self.log("dispatch!", args, kwargs)
|
114
|
+
|
115
|
+
s = args[1]
|
116
|
+
self.log("sum", s)
|
117
|
+
|
118
|
+
if s > 5 and args[0] > 0:
|
119
|
+
self.log("results big enough to continue")
|
120
|
+
|
121
|
+
self.blackboard[event_dispatch.cv_name].acquire()
|
122
|
+
self.blackboard[event_dispatch.queue_name].extend([
|
123
|
+
[
|
124
|
+
"WorkItemEvent",
|
125
|
+
args[0],
|
126
|
+
],
|
127
|
+
])
|
128
|
+
self.blackboard[event_dispatch.cv_name].notify(1)
|
129
|
+
self.blackboard[event_dispatch.cv_name].release()
|
130
|
+
else:
|
131
|
+
self.log("results not big enough or drained WorkItems, asking again")
|
132
|
+
|
133
|
+
self.blackboard["input_sem"].release()
|
134
|
+
|
135
|
+
def finish(self, event_dispatch, *args, **kwargs):
|
136
|
+
self.log("finish!", args, kwargs)
|
137
|
+
|
138
|
+
# this is an example of an 'Actor' / 'continuous-time' process
|
139
|
+
# a specialist in the system, that injects entrypoint Event(s)
|
140
|
+
# into the system
|
141
|
+
class KeyboardThread(threading.Thread):
|
142
|
+
def __init__(self, mutable_hb, blackboard, ed1):
|
143
|
+
self.mutable_hb = mutable_hb
|
144
|
+
self.blackboard = blackboard
|
145
|
+
self.ed1 = ed1
|
146
|
+
|
147
|
+
super(KeyboardThread, self).__init__()
|
148
|
+
|
149
|
+
def my_callback(self, x, mutable_hb, blackboard, ed1):
|
150
|
+
if len(x) == 0:
|
151
|
+
print("empty")
|
152
|
+
return True
|
153
|
+
|
154
|
+
x = int(x)
|
155
|
+
|
156
|
+
#evaluate the keyboard input
|
157
|
+
if x == 0:
|
158
|
+
print("turning off dispatch")
|
159
|
+
with ed1.dispatch_switch_mutex:
|
160
|
+
ed1.dispatch_switch = False
|
161
|
+
|
162
|
+
return True
|
163
|
+
|
164
|
+
elif x == 1:
|
165
|
+
print("turning on dispatch")
|
166
|
+
with ed1.dispatch_switch_mutex:
|
167
|
+
ed1.dispatch_switch = True
|
168
|
+
|
169
|
+
return True
|
170
|
+
|
171
|
+
elif x == -1:
|
172
|
+
print('exiting')
|
173
|
+
|
174
|
+
# stop this thread
|
175
|
+
with mutable_hb['hb_lock']:
|
176
|
+
mutable_hb['hb'] = False
|
177
|
+
|
178
|
+
# stop ed thread
|
179
|
+
blackboard[ed1.hb_key] = False
|
180
|
+
with blackboard[ed1.mutex_name]:
|
181
|
+
blackboard[ed1.cv_name].notify_all()
|
182
|
+
|
183
|
+
return True
|
184
|
+
|
185
|
+
elif x >= 2 and x <= 5:
|
186
|
+
print("dispatching WorkItemEvent(%d)" % (x))
|
187
|
+
|
188
|
+
blackboard[ed1.cv_name].acquire()
|
189
|
+
blackboard[ed1.queue_name].append(
|
190
|
+
[
|
191
|
+
"WorkItemEvent",
|
192
|
+
(
|
193
|
+
x
|
194
|
+
)
|
195
|
+
])
|
196
|
+
blackboard[ed1.cv_name].notify(1)
|
197
|
+
blackboard[ed1.cv_name].release()
|
198
|
+
|
199
|
+
return False
|
200
|
+
|
201
|
+
return False
|
202
|
+
|
203
|
+
def run(self):
|
204
|
+
local_hb = True
|
205
|
+
|
206
|
+
while local_hb:
|
207
|
+
self.blackboard["input_sem"].acquire()
|
208
|
+
print("unblocked!!!!!!!!!")
|
209
|
+
|
210
|
+
if not self.blackboard["ask"]:
|
211
|
+
print("no longer asking, break")
|
212
|
+
break
|
213
|
+
|
214
|
+
x = input('enter a number 2-5, 0 to turn off dispatch, 1 to turn on dispatch, -1 to exit\n')
|
215
|
+
|
216
|
+
release = self.my_callback(x, self.mutable_hb, self.blackboard, self.ed1)
|
217
|
+
if release:
|
218
|
+
self.blackboard["input_sem"].release()
|
219
|
+
|
220
|
+
with self.mutable_hb['hb_lock']:
|
221
|
+
local_hb = self.mutable_hb['hb']
|
222
|
+
|
223
|
+
def main():
|
224
|
+
# 0. Create `Blackboard` instance(s)
|
225
|
+
blackboard = Blackboard()
|
226
|
+
|
227
|
+
# 1. Populate the `Blackboard` with `Event` declarations (name : type pairs)
|
228
|
+
blackboard["WorkItemEvent"] = WorkItemEvent
|
229
|
+
blackboard["UncertaintEvent1"] = UncertaintEvent1
|
230
|
+
blackboard["UncertaintEvent2"] = UncertaintEvent2
|
231
|
+
blackboard["CheckEvent1"] = CheckEvent1
|
232
|
+
|
233
|
+
blackboard["result_mutex"] = threading.Lock()
|
234
|
+
blackboard["result1"] = 0
|
235
|
+
blackboard["result2"] = 0
|
236
|
+
|
237
|
+
blackboard["ask"] = True
|
238
|
+
blackboard["input_sem"] = threading.Semaphore(1)
|
239
|
+
|
240
|
+
# 2. Create `BlackboardQueueCVED` instance(s) with their individual `name` strings
|
241
|
+
ed1 = BlackboardQueueCVED(
|
242
|
+
blackboard,
|
243
|
+
"ed1"
|
244
|
+
)
|
245
|
+
blackboard["ed1"] = ed1
|
246
|
+
|
247
|
+
# 3. Stand up their `run` targets as threads
|
248
|
+
blackboard["ed1_thread"] = Thread(
|
249
|
+
target=ed1.run,
|
250
|
+
args=(
|
251
|
+
blackboard,
|
252
|
+
"ed1",
|
253
|
+
None,
|
254
|
+
bcolors.OKGREEN,
|
255
|
+
))
|
256
|
+
blackboard["ed1_thread"].start()
|
257
|
+
|
258
|
+
# main thread goes here
|
259
|
+
mutable_hb = {
|
260
|
+
"hb_lock" : threading.Lock(),
|
261
|
+
"hb" : True,
|
262
|
+
}
|
263
|
+
kthread = KeyboardThread(mutable_hb, blackboard, ed1)
|
264
|
+
kthread.start()
|
265
|
+
|
266
|
+
# 4. Best practice (thread hygiene): on program shutdown
|
267
|
+
# notify the `BlackboardQueueCVED` cvs and join their `run` threads
|
268
|
+
def signal_handler(signal, frame):
|
269
|
+
print("killing ed1_thread")
|
270
|
+
blackboard[ed1.hb_key] = False
|
271
|
+
with blackboard[ed1.mutex_name]:
|
272
|
+
blackboard[ed1.cv_name].notify_all()
|
273
|
+
blackboard["ed1_thread"].join()
|
274
|
+
|
275
|
+
blackboard["ask"] = False
|
276
|
+
blackboard["input_sem"].release()
|
277
|
+
|
278
|
+
print("shutting down")
|
279
|
+
sys.exit(0)
|
280
|
+
|
281
|
+
signal.signal(signal.SIGINT, signal_handler)
|
282
|
+
|
283
|
+
blackboard["ed1_thread"].join()
|
284
|
+
kthread.join()
|
285
|
+
|
286
|
+
if __name__ == '__main__':
|
287
|
+
main()
|
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
@@ -0,0 +1,237 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: eventdispatch
|
3
|
+
Version: 0.1.11
|
4
|
+
Summary: Event Dispatch: a discrete time synchronizer
|
5
|
+
Home-page: http://github.com/cyan-at/eventdispatch
|
6
|
+
Author: Charlie Yan
|
7
|
+
Author-email: Charlie Yan <cyanatg@gmail.com>
|
8
|
+
License:
|
9
|
+
Apache License
|
10
|
+
Version 2.0, January 2004
|
11
|
+
http://www.apache.org/licenses/
|
12
|
+
|
13
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
14
|
+
|
15
|
+
1. Definitions.
|
16
|
+
|
17
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
18
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
19
|
+
|
20
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
21
|
+
the copyright owner that is granting the License.
|
22
|
+
|
23
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
24
|
+
other entities that control, are controlled by, or are under common
|
25
|
+
control with that entity. For the purposes of this definition,
|
26
|
+
"control" means (i) the power, direct or indirect, to cause the
|
27
|
+
direction or management of such entity, whether by contract or
|
28
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
29
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
30
|
+
|
31
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
32
|
+
exercising permissions granted by this License.
|
33
|
+
|
34
|
+
"Source" form shall mean the preferred form for making modifications,
|
35
|
+
including but not limited to software source code, documentation
|
36
|
+
source, and configuration files.
|
37
|
+
|
38
|
+
"Object" form shall mean any form resulting from mechanical
|
39
|
+
transformation or translation of a Source form, including but
|
40
|
+
not limited to compiled object code, generated documentation,
|
41
|
+
and conversions to other media types.
|
42
|
+
|
43
|
+
"Work" shall mean the work of authorship, whether in Source or
|
44
|
+
Object form, made available under the License, as indicated by a
|
45
|
+
copyright notice that is included in or attached to the work
|
46
|
+
(an example is provided in the Appendix below).
|
47
|
+
|
48
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
49
|
+
form, that is based on (or derived from) the Work and for which the
|
50
|
+
editorial revisions, annotations, elaborations, or other modifications
|
51
|
+
represent, as a whole, an original work of authorship. For the purposes
|
52
|
+
of this License, Derivative Works shall not include works that remain
|
53
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
54
|
+
the Work and Derivative Works thereof.
|
55
|
+
|
56
|
+
"Contribution" shall mean any work of authorship, including
|
57
|
+
the original version of the Work and any modifications or additions
|
58
|
+
to that Work or Derivative Works thereof, that is intentionally
|
59
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
60
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
61
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
62
|
+
means any form of electronic, verbal, or written communication sent
|
63
|
+
to the Licensor or its representatives, including but not limited to
|
64
|
+
communication on electronic mailing lists, source code control systems,
|
65
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
66
|
+
Licensor for the purpose of discussing and improving the Work, but
|
67
|
+
excluding communication that is conspicuously marked or otherwise
|
68
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
69
|
+
|
70
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
71
|
+
on behalf of whom a Contribution has been received by Licensor and
|
72
|
+
subsequently incorporated within the Work.
|
73
|
+
|
74
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
copyright license to reproduce, prepare Derivative Works of,
|
78
|
+
publicly display, publicly perform, sublicense, and distribute the
|
79
|
+
Work and such Derivative Works in Source or Object form.
|
80
|
+
|
81
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
82
|
+
this License, each Contributor hereby grants to You a perpetual,
|
83
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
84
|
+
(except as stated in this section) patent license to make, have made,
|
85
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
86
|
+
where such license applies only to those patent claims licensable
|
87
|
+
by such Contributor that are necessarily infringed by their
|
88
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
89
|
+
with the Work to which such Contribution(s) was submitted. If You
|
90
|
+
institute patent litigation against any entity (including a
|
91
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
92
|
+
or a Contribution incorporated within the Work constitutes direct
|
93
|
+
or contributory patent infringement, then any patent licenses
|
94
|
+
granted to You under this License for that Work shall terminate
|
95
|
+
as of the date such litigation is filed.
|
96
|
+
|
97
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
98
|
+
Work or Derivative Works thereof in any medium, with or without
|
99
|
+
modifications, and in Source or Object form, provided that You
|
100
|
+
meet the following conditions:
|
101
|
+
|
102
|
+
(a) You must give any other recipients of the Work or
|
103
|
+
Derivative Works a copy of this License; and
|
104
|
+
|
105
|
+
(b) You must cause any modified files to carry prominent notices
|
106
|
+
stating that You changed the files; and
|
107
|
+
|
108
|
+
(c) You must retain, in the Source form of any Derivative Works
|
109
|
+
that You distribute, all copyright, patent, trademark, and
|
110
|
+
attribution notices from the Source form of the Work,
|
111
|
+
excluding those notices that do not pertain to any part of
|
112
|
+
the Derivative Works; and
|
113
|
+
|
114
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
115
|
+
distribution, then any Derivative Works that You distribute must
|
116
|
+
include a readable copy of the attribution notices contained
|
117
|
+
within such NOTICE file, excluding those notices that do not
|
118
|
+
pertain to any part of the Derivative Works, in at least one
|
119
|
+
of the following places: within a NOTICE text file distributed
|
120
|
+
as part of the Derivative Works; within the Source form or
|
121
|
+
documentation, if provided along with the Derivative Works; or,
|
122
|
+
within a display generated by the Derivative Works, if and
|
123
|
+
wherever such third-party notices normally appear. The contents
|
124
|
+
of the NOTICE file are for informational purposes only and
|
125
|
+
do not modify the License. You may add Your own attribution
|
126
|
+
notices within Derivative Works that You distribute, alongside
|
127
|
+
or as an addendum to the NOTICE text from the Work, provided
|
128
|
+
that such additional attribution notices cannot be construed
|
129
|
+
as modifying the License.
|
130
|
+
|
131
|
+
You may add Your own copyright statement to Your modifications and
|
132
|
+
may provide additional or different license terms and conditions
|
133
|
+
for use, reproduction, or distribution of Your modifications, or
|
134
|
+
for any such Derivative Works as a whole, provided Your use,
|
135
|
+
reproduction, and distribution of the Work otherwise complies with
|
136
|
+
the conditions stated in this License.
|
137
|
+
|
138
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
139
|
+
any Contribution intentionally submitted for inclusion in the Work
|
140
|
+
by You to the Licensor shall be under the terms and conditions of
|
141
|
+
this License, without any additional terms or conditions.
|
142
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
143
|
+
the terms of any separate license agreement you may have executed
|
144
|
+
with Licensor regarding such Contributions.
|
145
|
+
|
146
|
+
6. Trademarks. This License does not grant permission to use the trade
|
147
|
+
names, trademarks, service marks, or product names of the Licensor,
|
148
|
+
except as required for reasonable and customary use in describing the
|
149
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
150
|
+
|
151
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
152
|
+
agreed to in writing, Licensor provides the Work (and each
|
153
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
154
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
155
|
+
implied, including, without limitation, any warranties or conditions
|
156
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
157
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
158
|
+
appropriateness of using or redistributing the Work and assume any
|
159
|
+
risks associated with Your exercise of permissions under this License.
|
160
|
+
|
161
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
162
|
+
whether in tort (including negligence), contract, or otherwise,
|
163
|
+
unless required by applicable law (such as deliberate and grossly
|
164
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
165
|
+
liable to You for damages, including any direct, indirect, special,
|
166
|
+
incidental, or consequential damages of any character arising as a
|
167
|
+
result of this License or out of the use or inability to use the
|
168
|
+
Work (including but not limited to damages for loss of goodwill,
|
169
|
+
work stoppage, computer failure or malfunction, or any and all
|
170
|
+
other commercial damages or losses), even if such Contributor
|
171
|
+
has been advised of the possibility of such damages.
|
172
|
+
|
173
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
174
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
175
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
176
|
+
or other liability obligations and/or rights consistent with this
|
177
|
+
License. However, in accepting such obligations, You may act only
|
178
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
179
|
+
of any other Contributor, and only if You agree to indemnify,
|
180
|
+
defend, and hold each Contributor harmless for any liability
|
181
|
+
incurred by, or claims asserted against, such Contributor by reason
|
182
|
+
of your accepting any such warranty or additional liability.
|
183
|
+
|
184
|
+
END OF TERMS AND CONDITIONS
|
185
|
+
|
186
|
+
APPENDIX: How to apply the Apache License to your work.
|
187
|
+
|
188
|
+
To apply the Apache License to your work, attach the following
|
189
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
190
|
+
replaced with your own identifying information. (Don't include
|
191
|
+
the brackets!) The text should be enclosed in the appropriate
|
192
|
+
comment syntax for the file format. We also recommend that a
|
193
|
+
file or class name and description of purpose be included on the
|
194
|
+
same "printed page" as the copyright notice for easier
|
195
|
+
identification within third-party archives.
|
196
|
+
|
197
|
+
Copyright [yyyy] [name of copyright owner]
|
198
|
+
|
199
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
200
|
+
you may not use this file except in compliance with the License.
|
201
|
+
You may obtain a copy of the License at
|
202
|
+
|
203
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
204
|
+
|
205
|
+
Unless required by applicable law or agreed to in writing, software
|
206
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
207
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
208
|
+
See the License for the specific language governing permissions and
|
209
|
+
limitations under the License.
|
210
|
+
Project-URL: Homepage, https://github.com/cyan-at/eventdispatch
|
211
|
+
Project-URL: Issues, https://github.com/cyan-at/eventdispatch/issues
|
212
|
+
Classifier: Programming Language :: Python :: 3
|
213
|
+
Classifier: Operating System :: POSIX :: Linux
|
214
|
+
Requires-Python: >=3.9
|
215
|
+
Description-Content-Type: text/markdown
|
216
|
+
License-File: LICENSE
|
217
|
+
Requires-Dist: argparse
|
218
|
+
Requires-Dist: threading
|
219
|
+
|
220
|
+
# eventdispatch
|
221
|
+
Event Dispatch: a discrete time synchronizer
|
222
|
+
|
223
|
+
## Documentation
|
224
|
+
|
225
|
+
The latest documentation on [readthedocs](https://eventdispatch.readthedocs.io/en/latest/)
|
226
|
+
|
227
|
+
## python3: apt installation
|
228
|
+
```
|
229
|
+
sudo add-apt-repository ppa:cyanatlaunchpad/python3-eventdispatch-ppa
|
230
|
+
sudo apt update
|
231
|
+
sudo apt install python3-eventdispatch
|
232
|
+
```
|
233
|
+
|
234
|
+
## python3: pip installation
|
235
|
+
```
|
236
|
+
TODO
|
237
|
+
```
|
@@ -0,0 +1,10 @@
|
|
1
|
+
eventdispatch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
eventdispatch/aux1.py,sha256=u8XP5V2gZj1FlqEbLf9JWvz_1-Seh_Ds9fr-E2lzq8w,8178
|
3
|
+
eventdispatch/core.py,sha256=Pk0FUcQBCF2Bpq4-gfIc6fN8dxbXrgZV1Wjv8jx7O7E,6978
|
4
|
+
eventdispatch/example1.py,sha256=No8T2gnvAXXk5_mgpWIr8n8HYxcjKII-Bi5DKqjtA1U,8626
|
5
|
+
eventdispatch-0.1.11.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
6
|
+
eventdispatch-0.1.11.dist-info/METADATA,sha256=YiscE0K5kJ1wrJZFbr3Pp2-dvTShlNVycwLts0XjLoc,13944
|
7
|
+
eventdispatch-0.1.11.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
8
|
+
eventdispatch-0.1.11.dist-info/entry_points.txt,sha256=52gXPj1zjMPWj460qrTJ6RBn3XZKFoqgNdI4iDwYOGw,71
|
9
|
+
eventdispatch-0.1.11.dist-info/top_level.txt,sha256=EFnhw7vsL0B6wdGcB7YXLOUR-2QlTLFhAF8gwp43z-U,14
|
10
|
+
eventdispatch-0.1.11.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
eventdispatch
|