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

Dettach duplicated signal handler from workers #2413

Merged
merged 1 commit into from
Sep 17, 2020
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
8 changes: 8 additions & 0 deletions python/seldon_core/app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import os
import logging
import atexit

from multiprocessing.util import _exit_function
from typing import Dict, Union
from gunicorn.app.base import BaseApplication

logger = logging.getLogger(__name__)


def post_worker_init(worker):
# Remove the atexit handler set up by the parent process
# https://github.com/benoitc/gunicorn/issues/1391#issuecomment-467010209
atexit.unregister(_exit_function)


def accesslog(log_level: str) -> Union[str, None]:
"""
Enable / disable access log in Gunicorn depending on the log level.
Expand Down
26 changes: 17 additions & 9 deletions python/seldon_core/microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
UserModelApplication,
accesslog,
threads,
post_worker_init,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -53,18 +54,23 @@ def start_servers(
Auxilary flask process

"""
p2 = mp.Process(target=target2)
p2.daemon = True
p2.start()
p2 = None
if target2:
p2 = mp.Process(target=target2, daemon=True)
p2.start()

p3 = mp.Process(target=metrics_target)
p3.daemon = True
p3.start()
p3 = None
if metrics_target:
p3 = mp.Process(target=metrics_target, daemon=True)
p3.start()

target1()

p2.join()
p3.join()
if p2:
p2.join()

if p3:
p3.join()


def parse_parameters(parameters: Dict) -> Dict:
Expand Down Expand Up @@ -391,6 +397,7 @@ def rest_prediction_server():
"workers": args.workers,
"max_requests": args.max_requests,
"max_requests_jitter": args.max_requests_jitter,
"post_worker_init": post_worker_init,
}
app = seldon_microservice.get_rest_microservice(
user_object, seldon_metrics
Expand Down Expand Up @@ -452,6 +459,7 @@ def rest_metrics_server():
"timeout": 5000,
"max_requests": args.max_requests,
"max_requests_jitter": args.max_requests_jitter,
"post_worker_init": post_worker_init,
}
StandaloneApplication(app, options=options).run()

Expand All @@ -465,7 +473,7 @@ def rest_metrics_server():
else:
server2_func = None

logger.info("Starting servers")
logger.info("Starting servers")
start_servers(server1_func, server2_func, metrics_server_func)


Expand Down