smallneuron 2.2.7__tar.gz → 2.2.8__tar.gz
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.
- {smallneuron-2.2.7/src/smallneuron.egg-info → smallneuron-2.2.8}/PKG-INFO +1 -1
- {smallneuron-2.2.7 → smallneuron-2.2.8}/pyproject.toml +1 -1
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/smallneuron.py +2 -2
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/snwatcher.py +27 -24
- {smallneuron-2.2.7 → smallneuron-2.2.8/src/smallneuron.egg-info}/PKG-INFO +1 -1
- {smallneuron-2.2.7 → smallneuron-2.2.8}/.gitignore +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/LICENSE +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/README.md +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/example.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/setup.cfg +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/__init__.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/build +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.c +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.h +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.so +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/logger.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sndummy.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sngpio.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sninput.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/snmqtt.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/snserial.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sntimer.py +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron.egg-info/SOURCES.txt +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron.egg-info/dependency_links.txt +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron.egg-info/top_level.txt +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/PKG-INFO +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/SOURCES.txt +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/dependency_links.txt +0 -0
- {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/top_level.txt +0 -0
|
@@ -131,8 +131,8 @@ class EventManager:
|
|
|
131
131
|
# que generaran eventos
|
|
132
132
|
def watchEvent(self,event, event_params={}, data_pattern=None,
|
|
133
133
|
callback_obj=None, callback_function_args={},
|
|
134
|
-
mode="loop",period=1):
|
|
135
|
-
watcher=SnWatcher(self,event,event_params, data_pattern)
|
|
134
|
+
mode="loop",period=1, semaphore:threading.Semaphore=None):
|
|
135
|
+
watcher=SnWatcher(self,event,event_params, data_pattern,semaphore)
|
|
136
136
|
watcher.start(callback_obj,callback_function_args,mode,period)
|
|
137
137
|
return watcher
|
|
138
138
|
|
|
@@ -8,7 +8,6 @@ from datetime import datetime
|
|
|
8
8
|
|
|
9
9
|
log= Logger("smallneuron.snwatcher")
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
class SnWatcher():
|
|
13
12
|
'''
|
|
14
13
|
Cada instancia de esta clase monitorea la funcion callback() del bridge, con bridge_args como parametros,
|
|
@@ -21,16 +20,24 @@ class SnWatcher():
|
|
|
21
20
|
3. Si se repiten los elementos retornados por check() con los events_params mandan los de check()
|
|
22
21
|
una respuesta hasta que respuesta, bloqueando
|
|
23
22
|
'''
|
|
24
|
-
def __init__(self, eventManager, event, event_params={}, event_pattern=None):
|
|
23
|
+
def __init__(self, eventManager, event, event_params={}, event_pattern=None,semaphore:threading.Semaphore=None):
|
|
25
24
|
self.em=eventManager
|
|
26
25
|
self.event=event
|
|
27
26
|
self.event_params=event_params
|
|
28
27
|
self.event_pattern=event_pattern
|
|
29
28
|
self.stoploop=False
|
|
30
29
|
self.thread=None
|
|
31
|
-
self.
|
|
30
|
+
self._sem:threading.Semaphore=semaphore
|
|
32
31
|
log.debug("created")
|
|
33
32
|
|
|
33
|
+
def semAcquire(self):
|
|
34
|
+
if self._sem != None:
|
|
35
|
+
self._sem.acquire()
|
|
36
|
+
|
|
37
|
+
def semRelease(self):
|
|
38
|
+
if self._sem != None:
|
|
39
|
+
self._sem.release()
|
|
40
|
+
|
|
34
41
|
def start(self, callback_obj, callback_function_args={}, mode="loop",period=1):
|
|
35
42
|
'''
|
|
36
43
|
modos validos:
|
|
@@ -56,28 +63,24 @@ class SnWatcher():
|
|
|
56
63
|
return False
|
|
57
64
|
|
|
58
65
|
def _loop_callback(self, args):
|
|
59
|
-
log.debug("_loop_callback start",args)
|
|
66
|
+
log.debug(threading.get_ident(),"_loop_callback start",args)
|
|
60
67
|
try:
|
|
61
68
|
[callback_obj,callback_function_args,mode, period] = args
|
|
62
69
|
# Pasamos como argumento a la funcion externa un diccionario para los datos
|
|
63
70
|
# que necesite persistir entre llamados
|
|
64
|
-
self.
|
|
71
|
+
self.semAcquire()
|
|
65
72
|
while not self.stoploop:
|
|
66
73
|
try:
|
|
67
74
|
resp=callback_obj.callback(**callback_function_args)
|
|
75
|
+
self.semRelease()
|
|
68
76
|
except Exception as e:
|
|
69
|
-
log.warn("Exception from callback", e)
|
|
77
|
+
log.warn(threading.get_ident(),"Exception from callback", e)
|
|
70
78
|
# Nos olvidamos de esto y saltamos al proximo ciclo
|
|
71
|
-
self.
|
|
79
|
+
self.semRelease()
|
|
72
80
|
sleep(period)
|
|
73
|
-
self.
|
|
81
|
+
self.semAcquire()
|
|
74
82
|
continue
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
self.sem.release()
|
|
79
|
-
#log.debug("_loop_callback resp",resp)
|
|
80
|
-
|
|
83
|
+
|
|
81
84
|
# Si la respuesta no es un dict
|
|
82
85
|
# creamos uno con la respuesta como data
|
|
83
86
|
if type(resp) != dict:
|
|
@@ -88,30 +91,30 @@ class SnWatcher():
|
|
|
88
91
|
self.em.putEvent(self.event, dict(self.event_params,**resp))
|
|
89
92
|
log.info("trigger", self.event_params)
|
|
90
93
|
if mode=="match":
|
|
91
|
-
log.debug("_check loop
|
|
94
|
+
log.debug(threading.get_ident(),"_check loop match")
|
|
92
95
|
break
|
|
93
96
|
|
|
94
97
|
if mode=="noloop" :
|
|
95
|
-
log.debug("_check loop
|
|
98
|
+
log.debug(threading.get_ident(),"_check loop, noloop")
|
|
96
99
|
break
|
|
97
100
|
|
|
98
101
|
# default mode is loop
|
|
99
102
|
sleep(period)
|
|
100
|
-
self.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
log.debug("_check loop exit, stop")
|
|
103
|
+
self.semAcquire()
|
|
104
|
+
|
|
105
|
+
self.semRelease()
|
|
106
|
+
log.debug(threading.get_ident(),"_check loop exit, stop")
|
|
104
107
|
except Exception as e:
|
|
105
108
|
log.error(e)
|
|
106
109
|
log.error(traceback.format_exc())
|
|
107
|
-
log.debug("_check loop exit, exception")
|
|
108
|
-
self.
|
|
110
|
+
log.debug(threading.get_ident(),"_check loop exit, exception")
|
|
111
|
+
self.semRelease()
|
|
109
112
|
|
|
110
113
|
|
|
111
114
|
def stop(self, wait_to_finish=False):
|
|
112
|
-
self.
|
|
115
|
+
self.semAcquire()
|
|
113
116
|
self.stoploop=True
|
|
114
|
-
self.
|
|
117
|
+
self.semRelease()
|
|
115
118
|
if wait_to_finish:
|
|
116
119
|
self.thread.join()
|
|
117
120
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|