From 1c55e723366af6357979e449fcef56e57cef619a Mon Sep 17 00:00:00 2001 From: yuvipanda Date: Fri, 4 Jan 2019 13:27:16 -0800 Subject: [PATCH] Make compatible with python3.5 - No type annotations - No f-strings - Test on 3.5 on circleci --- .circleci/config.yml | 2 +- simpervisor/process.py | 20 +++++++++++--------- tests/child_scripts/signalsupervisor.py | 2 +- tests/child_scripts/simplehttpserver.py | 2 +- tests/test_atexitasync.py | 2 +- tests/test_ready.py | 6 +++--- tests/test_simpervisor.py | 2 +- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 78479fb..417d0f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: build: docker: - - image: circleci/python:3.6.1 + - image: circleci/python:3.5 working_directory: ~/repo steps: - checkout diff --git a/simpervisor/process.py b/simpervisor/process.py index bd39096..8aaa7e5 100644 --- a/simpervisor/process.py +++ b/simpervisor/process.py @@ -43,7 +43,7 @@ def __init__(self, name, *args, always_restart=False, ready_func=None, ready_tim # signals is synchronous. self._proc_lock = asyncio.Lock() - def _debug_log(self, action, message, extras=None): + def _debug_log(self, action, message, extras=None, *args): """ Log debug message with some added meta information. @@ -57,7 +57,7 @@ def _debug_log(self, action, message, extras=None): } if extras: base_extras.update(extras) - self.log.debug(message, extra=base_extras) + self.log.debug(message, extra=base_extras, *args) def _handle_signal(self, signal): # Child processes should handle SIGTERM / SIGINT & close, @@ -66,7 +66,7 @@ def _handle_signal(self, signal): self.proc.send_signal(signal) # Don't restart process after it is reaped self._killed = True - self._debug_log('signal', f'Propagated signal {signal} to {self.name}') + self._debug_log('signal', 'Propagated signal {} to {}', {}, signal, self.name) async def start(self): """ @@ -85,11 +85,11 @@ async def start(self): return if self._killed: raise KilledProcessError(f"Process {self.name} has already been explicitly killed") - self._debug_log('try-start', f'Trying to start {self.name}',) + self._debug_log('try-start', 'Trying to start {}', {}, self.name) self.proc = await asyncio.create_subprocess_exec( *self._proc_args, **self._proc_kwargs ) - self._debug_log('started', f'Started {self.name}',) + self._debug_log('started', 'Started {}', {}, self.name) self._killed = False self.running = True @@ -112,8 +112,9 @@ async def _restart_process_if_needed(self): # FIXME: Do we need to aquire a lock somewhere in this method? atexitasync.remove_handler(self._handle_signal) self._debug_log( - 'exited', f'{self.name} exited with code {retcode}', - {'code': retcode} + 'exited', '{} exited with code {}', + {'code': retcode}, + self.name, retcode ) self.running = False if (not self._killed) and (self.always_restart or retcode != 0): @@ -197,8 +198,9 @@ async def ready(self): cur_time = time.time() - start_time self._debug_log( 'ready-wait', - f'Readyness: {is_ready} after {cur_time} seconds, next check in {wait_time}s', - {'wait_time': wait_time, 'ready': is_ready, 'elapsed_time': cur_time} + 'Readyness: {} after {} seconds, next check in {}s', + {'wait_time': wait_time, 'ready': is_ready, 'elapsed_time': cur_time}, + is_ready, cur_time, wait_time ) if is_ready: return True diff --git a/tests/child_scripts/signalsupervisor.py b/tests/child_scripts/signalsupervisor.py index e896b94..3cd6379 100644 --- a/tests/child_scripts/signalsupervisor.py +++ b/tests/child_scripts/signalsupervisor.py @@ -17,7 +17,7 @@ async def main(): count = int(sys.argv[1]) pids = [] for i in range(count): - proc = SupervisedProcess(f'signalprinter-{i}', *[ + proc = SupervisedProcess('signalprinter-{}'.format(i), *[ sys.executable, signal_printer, '1' ]) diff --git a/tests/child_scripts/simplehttpserver.py b/tests/child_scripts/simplehttpserver.py index fe44137..a6c5851 100644 --- a/tests/child_scripts/simplehttpserver.py +++ b/tests/child_scripts/simplehttpserver.py @@ -7,7 +7,7 @@ from aiohttp import web wait_time = float(sys.argv[1]) -print(f'waiting {wait_time}') +print('waiting', wait_time) time.sleep(wait_time) PORT = os.environ['PORT'] diff --git a/tests/test_atexitasync.py b/tests/test_atexitasync.py index ab6add2..191cf62 100644 --- a/tests/test_atexitasync.py +++ b/tests/test_atexitasync.py @@ -31,7 +31,7 @@ def test_atexitasync(signum, handlercount): # Make sure the signal is handled by our handler in the code stdout, stderr = proc.communicate() expected_output = '\n'.join([ - f'handler {i} received {signum}' + 'handler {} received {}'.format(i, signum) for i in range(handlercount) ]) + '\n' diff --git a/tests/test_ready.py b/tests/test_ready.py index aa6e195..dfa7f69 100644 --- a/tests/test_ready.py +++ b/tests/test_ready.py @@ -22,14 +22,14 @@ async def test_ready(): ready_time = 3.0 async def _ready_func(p): - url = f'http://localhost:{port}' + url = 'http://localhost:{}'.format(port) async with aiohttp.ClientSession() as session: try: async with session.get(url) as resp: - logging.debug(f'Got code {resp.status} back from {url}') + logging.debug('Got code {} back from {}', resp.status, url) return resp.status == 200 except aiohttp.ClientConnectionError: - logging.debug(f'Connection to {url} refused') + logging.debug('Connection to {} refused', url) return False proc = SupervisedProcess( diff --git a/tests/test_simpervisor.py b/tests/test_simpervisor.py index 80cec11..cfe69c4 100644 --- a/tests/test_simpervisor.py +++ b/tests/test_simpervisor.py @@ -18,7 +18,7 @@ def sleep(retcode=0, time=SLEEP_TIME): """ return [ sys.executable, - '-c', f'import sys, time; time.sleep({time}); sys.exit({retcode})' + '-c', 'import sys, time; time.sleep({}); sys.exit({})'.format(time, retcode) ] @pytest.mark.asyncio