Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server adapters #904

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ async def watch_folder(apps_folder):
click.echo("--watch option has no effect in multi-process environment \n")
return

if server_config["server"].startswith(("wsgiref", "waitress", "rocket")):
if server_adapters.blocking.get(server_config["server"]):
# these servers block the main thread so we open a new thread for the file watcher
threading.Thread(
target=watch_folder_event_loop, args=(apps_folder,), daemon=True
Expand Down Expand Up @@ -1709,26 +1709,23 @@ def start_server(kwargs):

if not server_config["server"]:
if server_config["platform"] == "windows" or number_workers < 2:
server_config["server"] = "rocketServer"
server_config["server"] = "rocket"
else:
if not gunicorn:
logging.error("gunicorn not installed")
return
server_config["server"] = "gunicorn"

# Catch interrupts like Ctrl-C if needed
if server_config["server"] not in {"rocketServer", "wsgirefWsTwistedServer"}:
signal.signal(
signal.SIGINT,
lambda signal, frame: click.echo(
"KeyboardInterrupt (ID: {signal}) has been caught. Cleaning up..."
)
and sys.exit(0),
)
def stop_then_kill(sig, grame):
os.kill(os.getpid(), signal.SIGTERM)
time.sleep(2)
os.kill(os.getpid(), signal.SIGKILL)

signal.signal(signal.SIGINT, stop_then_kill)

params["server"] = server_config["server"]
if params["server"] in server_adapters.__all__:
params["server"] = getattr(server_adapters, params["server"])()
adapter = server_adapters.available.get(server_config["server"])
params["server"] = adapter or server_config["server"]
if number_workers > 1:
params["workers"] = number_workers
if server_config["server"] == "gunicorn":
Expand Down Expand Up @@ -2051,7 +2048,9 @@ def new_app(apps_folder, app_name, yes, scaffold_zip):
help="No prompt, assume yes to questions",
show_default=True,
)
@click.option("-H", "--host", default="127.0.0.1", help="Host listening IP", show_default=True)
@click.option(
"-H", "--host", default="127.0.0.1", help="Host listening IP", show_default=True
)
@click.option(
"-P", "--port", default=8000, type=int, help="Port number", show_default=True
)
Expand Down Expand Up @@ -2089,10 +2088,11 @@ def new_app(apps_folder, app_name, yes, scaffold_zip):
"--server",
default="default",
type=click.Choice(
["default", "wsgiref", "tornado", "gevent", "waitress"]
+ server_adapters.__all__
["default"] + list(server_adapters.available) + server_adapters.unavailable
),
help="Web server to use (unavailable: {})".format(
", ".join(server_adapters.unavailable)
),
help="Web server to use",
show_default=False,
)
@click.option(
Expand Down
Loading
Loading