rewrite keywords reserved in python 3.7 (`async` -> `nonsync`)

pull/2030/merge
sebres 7 years ago
parent 6b7cca07ae
commit ac9d5f61e7

@ -228,9 +228,9 @@ class Fail2banClient(Fail2banCmdLine, Thread):
return True return True
## ##
def configureServer(self, async=True, phase=None): def configureServer(self, nonsync=True, phase=None):
# if asynchron start this operation in the new thread: # if asynchronous start this operation in the new thread:
if async: if nonsync:
th = Thread(target=Fail2banClient.configureServer, args=(self, False, phase)) th = Thread(target=Fail2banClient.configureServer, args=(self, False, phase))
th.daemon = True th.daemon = True
return th.start() return th.start()

@ -164,21 +164,24 @@ class Fail2banServer(Fail2banCmdLine):
cli = self._Fail2banClient() cli = self._Fail2banClient()
return cli.start(argv) return cli.start(argv)
# Start the server: # Start the server, corresponding options:
from ..server.utils import Utils # background = True, if should be new process running in background, otherwise start in
# background = True, if should be new process running in background, otherwise start in foreground # foreground process will be forked in daemonize, inside of Server module.
# process will be forked in daemonize, inside of Server module. # nonsync = True, normally internal call only, if started from client, so configures
# async = True, if started from client, should... # the server via asynchronous thread.
background = self._conf["background"] background = self._conf["background"]
async = self._conf.get("async", False) nonsync = self._conf.get("async", False)
# If was started not from the client: # If was started not from the client:
if not async: if not nonsync:
# Load requirements on demand (we need utils only when asynchronous handling):
from ..server.utils import Utils
# Start new thread with client to read configuration and # Start new thread with client to read configuration and
# transfer it to the server: # transfer it to the server:
cli = self._Fail2banClient() cli = self._Fail2banClient()
phase = dict() phase = dict()
logSys.debug('Configure via async client thread') logSys.debug('Configure via async client thread')
cli.configureServer(async=True, phase=phase) cli.configureServer(phase=phase)
# wait, do not continue if configuration is not 100% valid: # wait, do not continue if configuration is not 100% valid:
Utils.wait_for(lambda: phase.get('ready', None) is not None, self._conf["timeout"], 0.001) Utils.wait_for(lambda: phase.get('ready', None) is not None, self._conf["timeout"], 0.001)
logSys.log(5, ' server phase %s', phase) logSys.log(5, ' server phase %s', phase)
@ -195,7 +198,7 @@ class Fail2banServer(Fail2banCmdLine):
pid = os.getpid() pid = os.getpid()
server = Fail2banServer.startServerDirect(self._conf, background) server = Fail2banServer.startServerDirect(self._conf, background)
# notify waiting thread server ready resp. done (background execution, error case, etc): # notify waiting thread server ready resp. done (background execution, error case, etc):
if not async: if not nonsync:
_server_ready() _server_ready()
# If forked - just exit other processes # If forked - just exit other processes
if pid != os.getpid(): # pragma: no cover if pid != os.getpid(): # pragma: no cover
@ -204,7 +207,7 @@ class Fail2banServer(Fail2banCmdLine):
cli._server = server cli._server = server
# wait for client answer "done": # wait for client answer "done":
if not async and cli: if not nonsync and cli:
Utils.wait_for(lambda: phase.get('done', None) is not None, self._conf["timeout"], 0.001) Utils.wait_for(lambda: phase.get('done', None) is not None, self._conf["timeout"], 0.001)
if not phase.get('done', False): if not phase.get('done', False):
if server: # pragma: no cover if server: # pragma: no cover

Loading…
Cancel
Save