smallneuron 2.2.6__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.6/src/smallneuron.egg-info → smallneuron-2.2.8}/PKG-INFO +1 -1
- {smallneuron-2.2.6 → smallneuron-2.2.8}/pyproject.toml +1 -1
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/smallneuron.py +2 -2
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/snwatcher.py +33 -19
- {smallneuron-2.2.6 → smallneuron-2.2.8/src/smallneuron.egg-info}/PKG-INFO +1 -1
- {smallneuron-2.2.6 → smallneuron-2.2.8}/.gitignore +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/LICENSE +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/README.md +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/example.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/setup.cfg +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/__init__.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/build +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.c +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.h +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.so +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/logger.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sndummy.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sngpio.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sninput.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/snmqtt.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/snserial.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sntimer.py +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron.egg-info/SOURCES.txt +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron.egg-info/dependency_links.txt +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron.egg-info/top_level.txt +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/PKG-INFO +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/SOURCES.txt +0 -0
- {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/dependency_links.txt +0 -0
- {smallneuron-2.2.6 → 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,17 +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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
try:
|
|
74
|
+
resp=callback_obj.callback(**callback_function_args)
|
|
75
|
+
self.semRelease()
|
|
76
|
+
except Exception as e:
|
|
77
|
+
log.warn(threading.get_ident(),"Exception from callback", e)
|
|
78
|
+
# Nos olvidamos de esto y saltamos al proximo ciclo
|
|
79
|
+
self.semRelease()
|
|
80
|
+
sleep(period)
|
|
81
|
+
self.semAcquire()
|
|
82
|
+
continue
|
|
83
|
+
|
|
70
84
|
# Si la respuesta no es un dict
|
|
71
85
|
# creamos uno con la respuesta como data
|
|
72
86
|
if type(resp) != dict:
|
|
@@ -77,30 +91,30 @@ class SnWatcher():
|
|
|
77
91
|
self.em.putEvent(self.event, dict(self.event_params,**resp))
|
|
78
92
|
log.info("trigger", self.event_params)
|
|
79
93
|
if mode=="match":
|
|
80
|
-
log.debug("_check loop
|
|
94
|
+
log.debug(threading.get_ident(),"_check loop match")
|
|
81
95
|
break
|
|
82
96
|
|
|
83
97
|
if mode=="noloop" :
|
|
84
|
-
log.debug("_check loop
|
|
98
|
+
log.debug(threading.get_ident(),"_check loop, noloop")
|
|
85
99
|
break
|
|
86
100
|
|
|
87
101
|
# default mode is loop
|
|
88
102
|
sleep(period)
|
|
89
|
-
self.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
log.debug("_check loop exit, stop")
|
|
103
|
+
self.semAcquire()
|
|
104
|
+
|
|
105
|
+
self.semRelease()
|
|
106
|
+
log.debug(threading.get_ident(),"_check loop exit, stop")
|
|
93
107
|
except Exception as e:
|
|
94
108
|
log.error(e)
|
|
95
109
|
log.error(traceback.format_exc())
|
|
96
|
-
log.debug("_check loop exit, exception")
|
|
97
|
-
self.
|
|
110
|
+
log.debug(threading.get_ident(),"_check loop exit, exception")
|
|
111
|
+
self.semRelease()
|
|
98
112
|
|
|
99
113
|
|
|
100
114
|
def stop(self, wait_to_finish=False):
|
|
101
|
-
self.
|
|
115
|
+
self.semAcquire()
|
|
102
116
|
self.stoploop=True
|
|
103
|
-
self.
|
|
117
|
+
self.semRelease()
|
|
104
118
|
if wait_to_finish:
|
|
105
119
|
self.thread.join()
|
|
106
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.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|