Skip to content

Commit

Permalink
Make compatible with python3.5
Browse files Browse the repository at this point in the history
- No type annotations
- No f-strings
- Test on 3.5 on circleci
  • Loading branch information
yuvipanda committed Jan 4, 2019
1 parent 8b0ddc5 commit 1c55e72
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions simpervisor/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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):
"""
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/child_scripts/signalsupervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
])
Expand Down
2 changes: 1 addition & 1 deletion tests/child_scripts/simplehttpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion tests/test_atexitasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
6 changes: 3 additions & 3 deletions tests/test_ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simpervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c55e72

Please sign in to comment.