Setup worker related optimizations.
(app, hostname=None)
| 790 | |
| 791 | |
| 792 | def setup_worker_optimizations(app, hostname=None): |
| 793 | """Setup worker related optimizations.""" |
| 794 | hostname = hostname or gethostname() |
| 795 | |
| 796 | # make sure custom Task.__call__ methods that calls super |
| 797 | # won't mess up the request/task stack. |
| 798 | _install_stack_protection() |
| 799 | |
| 800 | # all new threads start without a current app, so if an app is not |
| 801 | # passed on to the thread it will fall back to the "default app", |
| 802 | # which then could be the wrong app. So for the worker |
| 803 | # we set this to always return our app. This is a hack, |
| 804 | # and means that only a single app can be used for workers |
| 805 | # running in the same process. |
| 806 | app.set_current() |
| 807 | app.set_default() |
| 808 | |
| 809 | # evaluate all task classes by finalizing the app. |
| 810 | app.finalize() |
| 811 | |
| 812 | # set fast shortcut to task registry |
| 813 | _localized[:] = [ |
| 814 | app._tasks, |
| 815 | prepare_accept_content(app.conf.accept_content), |
| 816 | hostname, |
| 817 | ] |
| 818 | |
| 819 | app.use_fast_trace_task = True |
| 820 | |
| 821 | |
| 822 | def reset_worker_optimizations(app=current_app): |