-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
calling eventlib/gevent patching #6322
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
Changes from all commits
b4c82a7
dc8d20b
af5d81c
09403a7
cd48206
c488cc4
54356fb
d2def45
6dbcc13
bd95609
7f650c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,33 @@ | |
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def maybe_patch_concurrency(library): | ||
| """Patches gevent/eventlet libraries.""" | ||
|
|
||
| def patch_eventlet(): | ||
| import eventlet.debug | ||
|
|
||
| eventlet.monkey_patch() | ||
| blockdetect = float(os.environ.get('EVENTLET_NOBLOCK', 0)) | ||
| if blockdetect: | ||
| eventlet.debug.hub_blocking_detection(blockdetect, blockdetect) | ||
|
|
||
| def patch_gevent(): | ||
| import gevent.monkey | ||
| import gevent.signal | ||
|
|
||
| gevent.monkey.patch_all() | ||
|
|
||
| patches = { | ||
| 'eventlet': patch_eventlet, | ||
| 'gevent': patch_gevent | ||
| } | ||
|
|
||
| patcher = patches.get(library) | ||
| if patcher: | ||
| patcher() | ||
|
|
||
|
|
||
| class CeleryBeat(ParamType): | ||
| """Celery Beat flag.""" | ||
|
|
||
|
|
@@ -42,6 +69,8 @@ def __init__(self): | |
| def convert(self, value, param, ctx): | ||
| # Pools like eventlet/gevent needs to patch libs as early | ||
| # as possible. | ||
| maybe_patch_concurrency(value) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure that's the wrong hook for this.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open for suggestions. A possibility is to move this call to the command function itself, but then we can't reference the app in any of the |
||
|
|
||
| return concurrency.get_implementation( | ||
| value) or ctx.obj.app.conf.worker_pool | ||
|
|
||
|
|
@@ -111,7 +140,10 @@ def detach(path, argv, logfile=None, pidfile=None, uid=None, | |
|
|
||
|
|
||
| @click.command(cls=CeleryDaemonCommand, | ||
| context_settings={'allow_extra_args': True}) | ||
| context_settings={ | ||
| 'allow_extra_args': True, | ||
| 'ignore_unknown_options': True | ||
| }) | ||
| @click.option('-n', | ||
| '--hostname', | ||
| default=host_format(default_nodename(None)), | ||
|
|
@@ -173,7 +205,8 @@ def detach(path, argv, logfile=None, pidfile=None, uid=None, | |
| type=WORKERS_POOL, | ||
| cls=CeleryOption, | ||
| help_group="Pool Options", | ||
| help="Pool implementation.") | ||
| help="Pool implementation.", | ||
| is_eager=True) | ||
| @click.option('-E', | ||
| '--task-events', | ||
| '--events', | ||
|
|
@@ -265,12 +298,15 @@ def detach(path, argv, logfile=None, pidfile=None, uid=None, | |
| @click.option('--scheduler', | ||
| cls=CeleryOption, | ||
| help_group="Embedded Beat Options") | ||
| @click.argument('user_extra_params', nargs=-1, type=click.UNPROCESSED) | ||
| @click.pass_context | ||
| def worker(ctx, hostname=None, pool_cls=None, app=None, uid=None, gid=None, | ||
| def worker(ctx, hostname=None, pool_cls=None, uid=None, gid=None, | ||
| loglevel=None, logfile=None, pidfile=None, statedb=None, | ||
| user_extra_params=None, | ||
| **kwargs): | ||
| """Start worker instance. | ||
|
|
||
| \b | ||
| Examples | ||
| -------- | ||
| $ celery worker --app=proj -l info | ||
|
|
@@ -281,6 +317,23 @@ def worker(ctx, hostname=None, pool_cls=None, app=None, uid=None, gid=None, | |
|
|
||
| """ | ||
| app = ctx.obj.app | ||
|
|
||
| user_opts = app.user_options.get('worker') | ||
| if user_opts: | ||
| user_options = {} | ||
|
|
||
| def cb(_, param, val): | ||
| user_options[param.name] = val | ||
| return val | ||
|
|
||
| for x in user_opts: | ||
| x.callback = cb | ||
|
|
||
| cmd = click.Command("user", params=list(user_opts)) | ||
| cmd.parse_args(ctx, list(user_extra_params)) | ||
|
|
||
| kwargs.update(user_options) | ||
|
|
||
| if ctx.args: | ||
| try: | ||
| app.config_from_cmdline(ctx.args, namespace='worker') | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this to support preload options.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a compensation for that is done here:
https://github.com/celery/celery/pull/6322/files#diff-a6e64fe5a7c24a0e587e8c92e83b87b5R321
(of course, it is only a draft as it needs to be applied on beat and events as well. i wanted to get an approval for this idea before pursuing it)
there is a downside to this approach, but i'm not sure how else to get the user options only after the patching