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.
Files changed (29) hide show
  1. {smallneuron-2.2.6/src/smallneuron.egg-info → smallneuron-2.2.8}/PKG-INFO +1 -1
  2. {smallneuron-2.2.6 → smallneuron-2.2.8}/pyproject.toml +1 -1
  3. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/smallneuron.py +2 -2
  4. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/snwatcher.py +33 -19
  5. {smallneuron-2.2.6 → smallneuron-2.2.8/src/smallneuron.egg-info}/PKG-INFO +1 -1
  6. {smallneuron-2.2.6 → smallneuron-2.2.8}/.gitignore +0 -0
  7. {smallneuron-2.2.6 → smallneuron-2.2.8}/LICENSE +0 -0
  8. {smallneuron-2.2.6 → smallneuron-2.2.8}/README.md +0 -0
  9. {smallneuron-2.2.6 → smallneuron-2.2.8}/example.py +0 -0
  10. {smallneuron-2.2.6 → smallneuron-2.2.8}/setup.cfg +0 -0
  11. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/__init__.py +0 -0
  12. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/build +0 -0
  13. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.c +0 -0
  14. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.h +0 -0
  15. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.so +0 -0
  16. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/logger.py +0 -0
  17. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sndummy.py +0 -0
  18. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sngpio.py +0 -0
  19. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sninput.py +0 -0
  20. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/snmqtt.py +0 -0
  21. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/snserial.py +0 -0
  22. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron/sntimer.py +0 -0
  23. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron.egg-info/SOURCES.txt +0 -0
  24. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron.egg-info/dependency_links.txt +0 -0
  25. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron.egg-info/top_level.txt +0 -0
  26. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/PKG-INFO +0 -0
  27. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/SOURCES.txt +0 -0
  28. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/dependency_links.txt +0 -0
  29. {smallneuron-2.2.6 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smallneuron
3
- Version: 2.2.6
3
+ Version: 2.2.8
4
4
  Summary: Small Neuron Workflow
5
5
  Author-email: Andres Artigas <andres@artigas.cl>
6
6
  Project-URL: Homepage, https://github.com/pypa/sampleproject
@@ -3,7 +3,7 @@ requires = ["setuptools", "setuptools-scm"]
3
3
 
4
4
  [project]
5
5
  name = "smallneuron"
6
- version = "2.2.6"
6
+ version = "2.2.8"
7
7
  authors = [
8
8
  { name="Andres Artigas", email="andres@artigas.cl" },
9
9
  ]
@@ -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.sem=threading.Semaphore()
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.sem.acquire()
71
+ self.semAcquire()
65
72
  while not self.stoploop:
66
- resp=callback_obj.callback(**callback_function_args)
67
- self.sem.release()
68
- #log.debug("_loop_callback resp",resp)
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 exit, match")
94
+ log.debug(threading.get_ident(),"_check loop match")
81
95
  break
82
96
 
83
97
  if mode=="noloop" :
84
- log.debug("_check loop exit, noloop")
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.sem.acquire()
90
- self.sem.release()
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.sem.release()
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.sem.acquire()
115
+ self.semAcquire()
102
116
  self.stoploop=True
103
- self.sem.release()
117
+ self.semRelease()
104
118
  if wait_to_finish:
105
119
  self.thread.join()
106
120
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smallneuron
3
- Version: 2.2.6
3
+ Version: 2.2.8
4
4
  Summary: Small Neuron Workflow
5
5
  Author-email: Andres Artigas <andres@artigas.cl>
6
6
  Project-URL: Homepage, https://github.com/pypa/sampleproject
File without changes
File without changes
File without changes
File without changes
File without changes