whatsnew-2.5.rst 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. .. _whatsnew-2.5:
  2. ==========================
  3. What's new in Celery 2.5
  4. ==========================
  5. Celery aims to be a flexible and reliable, best-of-breed solution
  6. to process vast amounts of messages in a distributed fashion, while
  7. providing operations with the tools to maintain such a system.
  8. Celery has a large and diverse community of users and contributors,
  9. you should come join us :ref:`on IRC <irc-channel>`
  10. or :ref:`our mailing-list <mailing-list>`.
  11. To read more about Celery you should visit our `website`_.
  12. While this version is backward compatible with previous versions
  13. it is important that you read the following section.
  14. If you use Celery in combination with Django you must also
  15. read the `django-celery changelog`_ and upgrade to `django-celery 2.5`_.
  16. This version is officially supported on CPython 2.5, 2.6, 2.7, 3.2 and 3.3,
  17. as well as PyPy and Jython.
  18. .. _`website`: http://celeryproject.org/
  19. .. _`django-celery changelog`: http://bit.ly/djcelery-25-changelog
  20. .. _`django-celery 2.5`: http://pypi.python.org/pypi/django-celery/
  21. .. contents::
  22. :local:
  23. .. _v250-important:
  24. Important Notes
  25. ===============
  26. Broker connection pool now enabled by default
  27. ---------------------------------------------
  28. The default limit is 10 connections, if you have many threads/green-threads
  29. using connections at the same time you may want to tweak this limit
  30. to avoid contention.
  31. See the :setting:`BROKER_POOL_LIMIT` setting for more information.
  32. Also note that publishing tasks will be retried by default, to change
  33. this default or the default retry policy see
  34. :setting:`CELERY_TASK_PUBLISH_RETRY` and
  35. :setting:`CELERY_TASK_PUBLISH_RETRY_POLICY`.
  36. Rabbit Result Backend: Exchange is no longer *auto delete*
  37. ----------------------------------------------------------
  38. The exchange used for results in the Rabbit (AMQP) result backend
  39. used to have the *auto_delete* flag set, which could result in a
  40. race condition leading to an annoying warning.
  41. .. admonition:: For RabbitMQ users
  42. Old exchanges created with the *auto_delete* flag enabled has
  43. to be removed.
  44. The :program:`camqadm` command can be used to delete the
  45. previous exchange:
  46. .. code-block:: bash
  47. $ camqadm exchange.delete celeryresults
  48. As an alternative to deleting the old exchange you can
  49. configure a new name for the exchange::
  50. CELERY_RESULT_EXCHANGE = 'celeryresults2'
  51. But you have to make sure that all clients and workers
  52. use this new setting, so they are updated to use the same
  53. exchange name.
  54. Solution for hanging workers (but must be manually enabled)
  55. -----------------------------------------------------------
  56. The :setting:`CELERYD_FORCE_EXECV` setting has been added to solve
  57. a problem with deadlocks that originate when threads and fork is mixed
  58. together:
  59. .. code-block:: python
  60. CELERYD_FORCE_EXECV = True
  61. This setting is recommended for all users using the processes pool,
  62. but especially users also using time limits or a max tasks per child
  63. setting.
  64. - See `Python Issue 6721`_ to read more about this issue, and why
  65. resorting to :func:`~os.execv`` is the only safe solution.
  66. Enabling this option will result in a slight performance penalty
  67. when new child worker processes are started, and it will also increase
  68. memory usage (but many platforms are optimized, so the impact may be
  69. minimal). Considering that it ensures reliability when replacing
  70. lost worker processes, it should be worth it.
  71. - It's already the default behavior on Windows.
  72. - It will be the default behavior for all platforms in a future version.
  73. .. _`Python Issue 6721`: http://bugs.python.org/issue6721#msg140215
  74. .. _v250-optimizations:
  75. Optimizations
  76. =============
  77. - The code path used when the worker executes a task has been heavily
  78. optimized, meaning the worker is able to process a great deal
  79. more tasks/second compared to previous versions. As an example the solo
  80. pool can now process up to 15000 tasks/second on a 4 core MacBook Pro
  81. when using the `pylibrabbitmq`_ transport, where it previously
  82. could only do 5000 tasks/second.
  83. - The task error tracebacks are now much shorter.
  84. - Fixed a noticeable delay in task processing when rate limits are enabled.
  85. .. _`pylibrabbitmq`: http://pypi.python.org/pylibrabbitmq/
  86. .. _v250-deprecations:
  87. Deprecations
  88. ============
  89. Removals
  90. --------
  91. * The old :class:`TaskSet` signature of ``(task_name, list_of_tasks)``
  92. can no longer be used (originally scheduled for removal in 2.4).
  93. The deprecated ``.task_name`` and ``.task`` attributes has also been
  94. removed.
  95. * The functions ``celery.execute.delay_task``, ``celery.execute.apply``,
  96. and ``celery.execute.apply_async`` has been removed (originally)
  97. scheduled for removal in 2.3).
  98. * The built-in ``ping`` task has been removed (originally scheduled
  99. for removal in 2.3). Please use the ping broadcast command
  100. instead.
  101. * It is no longer possible to import ``subtask`` and ``TaskSet``
  102. from :mod:`celery.task.base`, please import them from :mod:`celery.task`
  103. instead (originally scheduled for removal in 2.4).
  104. Deprecations
  105. ------------
  106. * The :mod:`celery.decorators` module has changed status
  107. from pending deprecation to deprecated, and is scheduled for removal
  108. in version 4.0. The ``celery.task`` module must be used instead.
  109. .. _v250-news:
  110. News
  111. ====
  112. Timezone support
  113. ----------------
  114. Celery can now be configured to treat all incoming and outgoing dates
  115. as UTC, and the local timezone can be configured.
  116. This is not yet enabled by default, since enabling
  117. time zone support means workers running versions pre 2.5
  118. will be out of sync with upgraded workers.
  119. To enable UTC you have to set :setting:`CELERY_ENABLE_UTC`::
  120. CELERY_ENABLE_UTC = True
  121. When UTC is enabled, dates and times in task messages will be
  122. converted to UTC, and then converted back to the local timezone
  123. when received by a worker.
  124. You can change the local timezone using the :setting:`CELERY_TIMEZONE`
  125. setting. Installing the :mod:`pytz` library is recommended when
  126. using a custom timezone, to keep timezone definition up-to-date,
  127. but it will fallback to a system definition of the timezone if available.
  128. UTC will enabled by default in version 3.0.
  129. .. note::
  130. django-celery will use the local timezone as specified by the
  131. ``TIME_ZONE`` setting, it will also honor the new `USE_TZ`_ setting
  132. introuced in Django 1.4.
  133. .. _`USE_TZ`: https://docs.djangoproject.com/en/dev/topics/i18n/timezones/
  134. New security serializer using cryptographic signing
  135. ---------------------------------------------------
  136. A new serializer has been added that signs and verifies the signature
  137. of messages.
  138. The name of the new serializer is ``auth``, and needs additional
  139. configuration to work (see :ref:`conf-security`).
  140. .. seealso::
  141. :ref:`guide-security`
  142. Contributed by Mher Movsisyan.
  143. Experimental support for automatic module reloading
  144. ---------------------------------------------------
  145. Starting :program:`celeryd` with the :option:`--autoreload` option will
  146. enable the worker to watch for file system changes to all imported task
  147. modules imported (and also any non-task modules added to the
  148. :setting:`CELERY_IMPORTS` setting or the :option:`-I|--include` option).
  149. This is an experimental feature intended for use in development only,
  150. using auto-reload in production is discouraged as the behavior of reloading
  151. a module in Python is undefined, and may cause hard to diagnose bugs and
  152. crashes. Celery uses the same approach as the auto-reloader found in e.g.
  153. the Django ``runserver`` command.
  154. When auto-reload is enabled the worker starts an additional thread
  155. that watches for changes in the file system. New modules are imported,
  156. and already imported modules are reloaded whenever a change is detected,
  157. and if the processes pool is used the child processes will finish the work
  158. they are doing and exit, so that they can be replaced by fresh processes
  159. effectively reloading the code.
  160. File system notification backends are pluggable, and Celery comes with three
  161. implementations:
  162. * inotify (Linux)
  163. Used if the :mod:`pyinotify` library is installed.
  164. If you are running on Linux this is the recommended implementation,
  165. to install the :mod:`pyinotify` library you have to run the following
  166. command:
  167. .. code-block:: bash
  168. $ pip install pyinotify
  169. * kqueue (OS X/BSD)
  170. * stat
  171. The fallback implementation simply polls the files using ``stat`` and is very
  172. expensive.
  173. You can force an implementation by setting the :envvar:`CELERYD_FSNOTIFY`
  174. environment variable:
  175. .. code-block:: bash
  176. $ env CELERYD_FSNOTIFY=stat celeryd -l info --autoreload
  177. Contributed by Mher Movsisyan.
  178. New :setting:`CELERY_ANNOTATIONS` setting
  179. -----------------------------------------
  180. This new setting enables the configuration to modify task classes
  181. and their attributes.
  182. The setting can be a dict, or a list of annotation objects that filter
  183. for tasks and return a map of attributes to change.
  184. As an example, this is an annotation to change the ``rate_limit`` attribute
  185. for the ``tasks.add`` task:
  186. .. code-block:: python
  187. CELERY_ANNOTATIONS = {'tasks.add': {'rate_limit': '10/s'}}
  188. or change the same for all tasks:
  189. .. code-block:: python
  190. CELERY_ANNOTATIONS = {'*': {'rate_limit': '10/s'}}
  191. You can change methods too, for example the ``on_failure`` handler:
  192. .. code-block:: python
  193. def my_on_failure(self, exc, task_id, args, kwargs, einfo):
  194. print('Oh no! Task failed: %r' % (exc, ))
  195. CELERY_ANNOTATIONS = {'*': {'on_failure': my_on_failure}}
  196. If you need more flexibility then you can also create objects
  197. that filter for tasks to annotate:
  198. .. code-block:: python
  199. class MyAnnotate(object):
  200. def annotate(self, task):
  201. if task.name.startswith('tasks.'):
  202. return {'rate_limit': '10/s'}
  203. CELERY_ANNOTATIONS = (MyAnnotate(), {...})
  204. ``current`` provides the currently executing task
  205. -------------------------------------------------
  206. The new :data:`celery.task.current` proxy will always give the currently
  207. executing task.
  208. **Example**:
  209. .. code-block:: python
  210. from celery.task import current, task
  211. @task
  212. def update_twitter_status(auth, message):
  213. twitter = Twitter(auth)
  214. try:
  215. twitter.update_status(message)
  216. except twitter.FailWhale, exc:
  217. # retry in 10 seconds.
  218. current.retry(countdown=10, exc=exc)
  219. Previously you would have to type ``update_twitter_status.retry(...)``
  220. here, which can be annoying for long task names.
  221. .. note::
  222. This will not work if the task function is called directly, i.e:
  223. ``update_twitter_status(a, b)``. For that to work ``apply`` must
  224. be used: ``update_twitter_status.apply((a, b))``.
  225. In Other News
  226. -------------
  227. - Now depends on Kombu 2.1.0.
  228. - Efficient Chord support for the memcached backend (Issue #533)
  229. This means memcached joins Redis in the ability to do non-polling
  230. chords.
  231. Contributed by Dan McGee.
  232. - Adds Chord support for the Rabbit result backend (amqp)
  233. The Rabbit result backend can now use the fallback chord solution.
  234. - Sending :sig:`QUIT` to celeryd will now cause it cold terminate.
  235. That is, it will not finish executing the tasks it is currently
  236. working on.
  237. Contributed by Alec Clowes.
  238. - New "detailed" mode for the Cassandra backend.
  239. Allows to have a "detailed" mode for the Cassandra backend.
  240. Basically the idea is to keep all states using Cassandra wide columns.
  241. New states are then appended to the row as new columns, the last state
  242. being the last column.
  243. See the :setting:`CASSANDRA_DETAILED_MODE` setting.
  244. Contributed by Steeve Morin.
  245. - The crontab parser now matches Vixie Cron behavior when parsing ranges
  246. with steps (e.g. 1-59/2).
  247. Contributed by Daniel Hepper.
  248. - celerybeat can now be configured on the command-line like celeryd.
  249. Additional configuration must be added at the end of the argument list
  250. followed by ``--``, for example:
  251. .. code-block:: bash
  252. $ celerybeat -l info -- celerybeat.max_loop_interval=10.0
  253. - Now limits the number of frames in a traceback so that celeryd does not
  254. crash on maximum recursion limit exceeded exceptions (Issue #615).
  255. The limit is set to the current recursion limit divided by 8 (which
  256. is 125 by default).
  257. To get or set the current recursion limit use
  258. :func:`sys.getrecursionlimit` and :func:`sys.setrecursionlimit`.
  259. - More information is now preserved in the pickleable traceback.
  260. This has been added so that Sentry can show more details.
  261. Contributed by Sean O'Connor.
  262. - CentOS init script has been updated and should be more flexible.
  263. Contributed by Andrew McFague.
  264. - MongoDB result backend now supports ``forget()``.
  265. Contributed by Andrew McFague
  266. - ``task.retry()`` now re-raises the original exception keeping
  267. the original stack trace.
  268. Suggested by ojii.
  269. - The `--uid` argument to daemons now uses ``initgroups()`` to set
  270. groups to all the groups the user is a member of.
  271. Contributed by Łukasz Oleś.
  272. - celeryctl: Added ``shell`` command.
  273. The shell will have the current_app (``celery``) and all tasks
  274. automatically added to locals.
  275. - celeryctl: Added ``migrate`` command.
  276. The migrate command moves all tasks from one broker to another.
  277. Note that this is experimental and you should have a backup
  278. of the data before proceeding.
  279. **Examples**:
  280. .. code-block:: bash
  281. $ celeryctl migrate redis://localhost amqp://localhost
  282. $ celeryctl migrate amqp://localhost//v1 amqp://localhost//v2
  283. $ python manage.py celeryctl migrate django:// redis://
  284. * Routers can now override the ``exchange`` and ``routing_key`` used
  285. to create missing queues (Issue #577).
  286. By default this will always use the name of the queue,
  287. but you can now have a router return exchange and routing_key keys
  288. to set them.
  289. This is useful when using routing classes which decides a destination
  290. at runtime.
  291. Contributed by Akira Matsuzaki.
  292. - Redis result backend: Adds support for a ``max_connections`` parameter.
  293. It is now possible to configure the maximum number of
  294. simultaneous connections in the Redis connection pool used for
  295. results.
  296. The default max connections setting can be configured using the
  297. :setting:`CELERY_REDIS_MAX_CONNECTIONS` setting,
  298. or it can be changed individually by ``RedisBackend(max_connections=int)``.
  299. Contributed by Steeve Morin.
  300. - Redis result backend: Adds the ability to wait for results without polling.
  301. Contributed by Steeve Morin.
  302. - MongoDB result backend: Now supports save and restore taskset.
  303. Contributed by Julien Poissonnier.
  304. - There's a new :ref:`guide-security` guide in the documentation.
  305. - The init scripts has been updated, and many bugs fixed.
  306. Contributed by Chris Streeter.
  307. - User (tilde) is now expanded in command-line arguments.
  308. - Can now configure CELERYCTL envvar in :file:`/etc/default/celeryd`.
  309. While not necessary for operation, :program:`celeryctl` is used for the
  310. ``celeryd status`` command, and the path to :program:`celeryctl` must be
  311. configured for that to work.
  312. The daemonization cookbook contains examples.
  313. Contributed by Jude Nagurney.
  314. - The MongoDB result backend can now use Replica Sets.
  315. Contributed by Ivan Metzlar.
  316. - gevent: Now supports autoscaling (Issue #599).
  317. Contributed by Mark Lavin.
  318. - multiprocessing: Mediator thread is now always enabled,
  319. even though rate limits are disabled, as the pool semaphore
  320. is known to block the main thread, causing broadcast commands and
  321. shutdown to depend on the semaphore being released.
  322. Fixes
  323. =====
  324. - Exceptions that are re-raised with a new exception object now keeps
  325. the original stack trace.
  326. - Windows: Fixed the ``no handlers found for multiprocessing`` warning.
  327. - Windows: The ``celeryd`` program can now be used.
  328. Previously Windows users had to launch celeryd using
  329. ``python -m celery.bin.celeryd``.
  330. - Redis result backend: Now uses ``SETEX`` command to set result key,
  331. and expiry atomically.
  332. Suggested by yaniv-aknin.
  333. - celeryd: Fixed a problem where shutdown hanged when Ctrl+C was used to
  334. terminate.
  335. - celeryd: No longer crashes when channel errors occur.
  336. Fix contributed by Roger Hu.
  337. - Fixed memory leak in the eventlet pool, caused by the
  338. use of ``greenlet.getcurrent``.
  339. Fix contributed by Ignas Mikalajūnas.
  340. - Cassandra backend: No longer uses :func:`pycassa.connect` which is
  341. deprecated since :mod:`pycassa` 1.4.
  342. Fix contributed by Jeff Terrace.
  343. - Fixed unicode decode errors that could occur while sending error emails.
  344. Fix contributed by Seong Wun Mun.
  345. - ``celery.bin`` programs now always defines ``__package__`` as recommended
  346. by PEP-366.
  347. - ``send_task`` now emits a warning when used in combination with
  348. :setting:`CELERY_ALWAYS_EAGER` (Issue #581).
  349. Contributed by Mher Movsisyan.
  350. - ``apply_async`` now forwards the original keyword arguments to ``apply``
  351. when :setting:`CELERY_ALWAYS_EAGER` is enabled.
  352. - celeryev now tries to re-establish the connection if the connection
  353. to the broker is lost (Issue #574).
  354. - celeryev: Fixed a crash occurring if a task has no associated worker
  355. information.
  356. Fix contributed by Matt Williamson.
  357. - The current date and time is now consistently taken from the current loaders
  358. ``now`` method.
  359. - Now shows helpful error message when given a config module ending in
  360. ``.py`` that can't be imported.
  361. - celeryctl: The ``--expires`` and ``-eta`` arguments to the apply command
  362. can now be an ISO-8601 formatted string.
  363. - celeryctl now exits with exit status ``EX_UNAVAILABLE`` (69) if no replies
  364. have been received.