Mercurial > templog
comparison py/tempserver.py @ 533:815f811f6a65
Fixed some warnings
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 28 Apr 2015 22:44:10 +0800 |
parents | 9b1d71310c83 |
children | 0a1b642e3086 |
comparison
equal
deleted
inserted
replaced
532:9b1d71310c83 | 533:815f811f6a65 |
---|---|
46 if self.fridge is None: | 46 if self.fridge is None: |
47 raise Exception("Tempserver.run() must be within 'with Tempserver() as server'") | 47 raise Exception("Tempserver.run() must be within 'with Tempserver() as server'") |
48 | 48 |
49 # XXX do these go here or in __enter_() ? | 49 # XXX do these go here or in __enter_() ? |
50 self.start_time = self.now() | 50 self.start_time = self.now() |
51 tasks = ( | 51 runloops = [ |
52 self.fridge.run(), | 52 self.fridge.run(), |
53 self.sensors.run(), | 53 self.sensors.run(), |
54 self.uploader.run(), | 54 self.uploader.run(), |
55 ) | 55 ] |
56 | 56 |
57 loop = asyncio.get_event_loop() | 57 loop = asyncio.get_event_loop() |
58 try: | 58 try: |
59 result_tasks = loop.run_until_complete(asyncio.wait(tasks, return_when=asyncio.FIRST_EXCEPTION)) | 59 loop.run_until_complete(asyncio.gather(*runloops)) |
60 # use the results so that exceptions get thrown | |
61 [t.result() for x in result_tasks for t in x] | |
62 except KeyboardInterrupt: | 60 except KeyboardInterrupt: |
63 print('ctrl-c') | 61 print('\nctrl-c') |
64 pass | |
65 finally: | 62 finally: |
63 # loop.close() seems necessary otherwise get warnings about signal handlers | |
66 loop.close() | 64 loop.close() |
67 | 65 |
68 def now(self): | 66 def now(self): |
69 return utils.monotonic_time() | 67 return utils.monotonic_time() |
70 | 68 |
108 # For now we just sleep, ignore the _wakeup | 106 # For now we just sleep, ignore the _wakeup |
109 try: | 107 try: |
110 yield from asyncio.wait_for(self._wakeup.wait(), timeout=timeout) | 108 yield from asyncio.wait_for(self._wakeup.wait(), timeout=timeout) |
111 except asyncio.TimeoutError: | 109 except asyncio.TimeoutError: |
112 pass | 110 pass |
113 | 111 |
114 def _reload_signal(self): | 112 def _reload_signal(self): |
115 try: | 113 try: |
116 self.params.load() | 114 self.params.load() |
117 L("Reloaded.") | 115 L("Reloaded.") |
118 self._wakeup.set() | 116 self._wakeup.set() |