Remove dependency on requests library.

Change auto reloader enviroment varible name to SANIC_SERVER_RUNNING
Fix some typo mistakes, flake uncompatibilities and such problems.
Raise NotImplementedError for operating systems except posix systems for auto reloading.
This commit is contained in:
Yaser Amiri
2017-12-26 19:17:13 +03:30
parent 3fe3c2c79f
commit 81494453b0
8 changed files with 68 additions and 39 deletions

View File

@@ -645,8 +645,13 @@ class Sanic:
try:
self.is_running = True
if workers == 1:
if os.name == 'posix' and auto_reload and \
os.environ.get('MAIN_PROCESS_RUNNED') != 'true':
if auto_reload and os.name != 'posix':
# This condition must be removed after implementing
# auto reloader for other operating systems.
raise NotImplementedError
if auto_reload and \
os.environ.get('SANIC_SERVER_RUNNING') != 'true':
reloader_helpers.watchdog(2)
else:
serve(**server_settings)
@@ -808,14 +813,14 @@ class Sanic:
logger.setLevel(logging.DEBUG)
if self.config.LOGO is not None and \
os.environ.get('MAIN_PROCESS_RUNNED') != 'true':
os.environ.get('SANIC_SERVER_RUNNING') != 'true':
logger.debug(self.config.LOGO)
if run_async:
server_settings['run_async'] = True
# Serve
if host and port and os.environ.get('MAIN_PROCESS_RUNNED') != 'true':
if host and port and os.environ.get('SANIC_SERVER_RUNNING') != 'true':
proto = "http"
if ssl is not None:
proto = "https"

View File

@@ -7,7 +7,9 @@ from multiprocessing import Process
def _iter_module_files():
"""This iterates over all relevant Python files. It goes through all
"""This iterates over all relevant Python files.
It goes through all
loaded files from modules, all files in folders of already loaded modules
as well as all files reachable through a package.
"""
@@ -38,12 +40,12 @@ def _get_args_for_reloading():
def restart_with_reloader():
"""Create a new process and a subprocess in it
with the same arguments as this one.
"""Create a new process and a subprocess in it with the same arguments as
this one.
"""
args = _get_args_for_reloading()
new_environ = os.environ.copy()
new_environ['MAIN_PROCESS_RUNNED'] = 'true'
new_environ['SANIC_SERVER_RUNNING'] = 'true'
cmd = ' '.join(args)
worker_process = Process(
target=subprocess.call, args=(cmd,),
@@ -58,7 +60,7 @@ def kill_process_children_unix(pid):
:param pid: PID of process (process ID)
:return: Nothing
"""
root_process_path = "/proc/%s/task/%s/children" % (pid, pid)
root_process_path = "/proc/{pid}/task/{pid}/children".format(pid=pid)
if not os.path.isfile(root_process_path):
return
with open(root_process_path) as children_list_file:
@@ -87,12 +89,11 @@ def kill_program_completly(proc):
def watchdog(sleep_interval):
"""Whatch project files, restart worker process if a change happened.
"""Watch project files, restart worker process if a change happened.
:param sleep_interval: interval in second.
:return: Nothing
"""
mtimes = {}
worker_process = restart_with_reloader()
signal.signal(