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.
Files changed (29) hide show
  1. {smallneuron-2.2.7/src/smallneuron.egg-info → smallneuron-2.2.8}/PKG-INFO +1 -1
  2. {smallneuron-2.2.7 → smallneuron-2.2.8}/pyproject.toml +1 -1
  3. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/smallneuron.py +2 -2
  4. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/snwatcher.py +27 -24
  5. {smallneuron-2.2.7 → smallneuron-2.2.8/src/smallneuron.egg-info}/PKG-INFO +1 -1
  6. {smallneuron-2.2.7 → smallneuron-2.2.8}/.gitignore +0 -0
  7. {smallneuron-2.2.7 → smallneuron-2.2.8}/LICENSE +0 -0
  8. {smallneuron-2.2.7 → smallneuron-2.2.8}/README.md +0 -0
  9. {smallneuron-2.2.7 → smallneuron-2.2.8}/example.py +0 -0
  10. {smallneuron-2.2.7 → smallneuron-2.2.8}/setup.cfg +0 -0
  11. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/__init__.py +0 -0
  12. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/build +0 -0
  13. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.c +0 -0
  14. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.h +0 -0
  15. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/gpio_h3.so +0 -0
  16. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/logger.py +0 -0
  17. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sndummy.py +0 -0
  18. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sngpio.py +0 -0
  19. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sninput.py +0 -0
  20. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/snmqtt.py +0 -0
  21. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/snserial.py +0 -0
  22. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron/sntimer.py +0 -0
  23. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron.egg-info/SOURCES.txt +0 -0
  24. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron.egg-info/dependency_links.txt +0 -0
  25. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron.egg-info/top_level.txt +0 -0
  26. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/PKG-INFO +0 -0
  27. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/SOURCES.txt +0 -0
  28. {smallneuron-2.2.7 → smallneuron-2.2.8}/src/smallneuron_pelainux.egg-info/dependency_links.txt +0 -0
  29. {smallneuron-2.2.7 → 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.7
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.7"
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,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.sem.acquire()
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.sem.release()
79
+ self.semRelease()
72
80
  sleep(period)
73
- self.sem.acquire()
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 exit, match")
94
+ log.debug(threading.get_ident(),"_check loop match")
92
95
  break
93
96
 
94
97
  if mode=="noloop" :
95
- log.debug("_check loop exit, noloop")
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.sem.acquire()
101
- self.sem.release()
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.sem.release()
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.sem.acquire()
115
+ self.semAcquire()
113
116
  self.stoploop=True
114
- self.sem.release()
117
+ self.semRelease()
115
118
  if wait_to_finish:
116
119
  self.thread.join()
117
120
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smallneuron
3
- Version: 2.2.7
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