/usr/share/doc/python-celery-doc/html/faq.html is in python-celery-doc 2.5.3-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Frequently Asked Questions — Celery 2.5.3 documentation</title>
<link rel="stylesheet" href="_static/celery.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/issuetracker.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '2.5.3',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Celery 2.5.3 documentation" href="index.html" />
<link rel="next" title="What’s new in Celery 2.5" href="whatsnew-2.5.html" />
<link rel="prev" title="Tutorial: Creating a click counter using Kombu and celery" href="tutorials/clickcounter.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="whatsnew-2.5.html" title="What’s new in Celery 2.5"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="tutorials/clickcounter.html" title="Tutorial: Creating a click counter using Kombu and celery"
accesskey="P">previous</a> |</li>
<li><a href="index.html">Celery 2.5.3 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="deck">
<p>
This document describes Celery 2.5. For development docs,
<a href="http://ask.github.com/celery/faq.html">go here</a>.
</p>
</div>
<div class="section" id="frequently-asked-questions">
<span id="faq"></span><h1>Frequently Asked Questions<a class="headerlink" href="#frequently-asked-questions" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#general" id="id1">General</a><ul>
<li><a class="reference internal" href="#what-kinds-of-things-should-i-use-celery-for" id="id2">What kinds of things should I use Celery for?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#misconceptions" id="id3">Misconceptions</a><ul>
<li><a class="reference internal" href="#is-celery-dependent-on-pickle" id="id4">Is Celery dependent on pickle?</a></li>
<li><a class="reference internal" href="#is-celery-for-django-only" id="id5">Is Celery for Django only?</a></li>
<li><a class="reference internal" href="#do-i-have-to-use-amqp-rabbitmq" id="id6">Do I have to use AMQP/RabbitMQ?</a></li>
<li><a class="reference internal" href="#is-celery-multilingual" id="id7">Is Celery multilingual?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#troubleshooting" id="id8">Troubleshooting</a><ul>
<li><a class="reference internal" href="#mysql-is-throwing-deadlock-errors-what-can-i-do" id="id9">MySQL is throwing deadlock errors, what can I do?</a></li>
<li><a class="reference internal" href="#celeryd-is-not-doing-anything-just-hanging" id="id10">celeryd is not doing anything, just hanging</a></li>
<li><a class="reference internal" href="#task-results-aren-t-reliably-returning" id="id11">Task results aren’t reliably returning</a></li>
<li><a class="reference internal" href="#why-is-task-delay-apply-celeryd-just-hanging" id="id12">Why is Task.delay/apply*/celeryd just hanging?</a></li>
<li><a class="reference internal" href="#does-it-work-on-freebsd" id="id13">Does it work on FreeBSD?</a></li>
<li><a class="reference internal" href="#i-m-having-integrityerror-duplicate-key-errors-why" id="id14">I’m having <cite>IntegrityError: Duplicate Key</cite> errors. Why?</a></li>
<li><a class="reference internal" href="#why-aren-t-my-tasks-processed" id="id15">Why aren’t my tasks processed?</a></li>
<li><a class="reference internal" href="#why-won-t-my-task-run" id="id16">Why won’t my Task run?</a></li>
<li><a class="reference internal" href="#why-won-t-my-periodic-task-run" id="id17">Why won’t my periodic task run?</a></li>
<li><a class="reference internal" href="#how-do-i-discard-all-waiting-tasks" id="id18">How do I discard all waiting tasks?</a></li>
<li><a class="reference internal" href="#i-ve-discarded-messages-but-there-are-still-messages-left-in-the-queue" id="id19">I’ve discarded messages, but there are still messages left in the queue?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#results" id="id20">Results</a><ul>
<li><a class="reference internal" href="#how-do-i-get-the-result-of-a-task-if-i-have-the-id-that-points-there" id="id21">How do I get the result of a task if I have the ID that points there?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#security" id="id22">Security</a><ul>
<li><a class="reference internal" href="#isn-t-using-pickle-a-security-concern" id="id23">Isn’t using <cite>pickle</cite> a security concern?</a></li>
<li><a class="reference internal" href="#can-messages-be-encrypted" id="id24">Can messages be encrypted?</a></li>
<li><a class="reference internal" href="#is-it-safe-to-run-celeryd-as-root" id="id25">Is it safe to run <strong class="program">celeryd</strong> as root?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#brokers" id="id26">Brokers</a><ul>
<li><a class="reference internal" href="#why-is-rabbitmq-crashing" id="id27">Why is RabbitMQ crashing?</a></li>
<li><a class="reference internal" href="#can-i-use-celery-with-activemq-stomp" id="id28">Can I use Celery with ActiveMQ/STOMP?</a></li>
<li><a class="reference internal" href="#what-features-are-not-supported-when-not-using-an-amqp-broker" id="id29">What features are not supported when not using an AMQP broker?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#tasks" id="id30">Tasks</a><ul>
<li><a class="reference internal" href="#how-can-i-reuse-the-same-connection-when-applying-tasks" id="id31">How can I reuse the same connection when applying tasks?</a></li>
<li><a class="reference internal" href="#sudo-in-a-subprocess-returns-none" id="id32">Sudo in a <a class="reference external" href="http://docs.python.org/library/subprocess.html#subprocess" title="(in Python v2.7)"><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> returns <tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a></li>
<li><a class="reference internal" href="#why-do-workers-delete-tasks-from-the-queue-if-they-are-unable-to-process-them" id="id33">Why do workers delete tasks from the queue if they are unable to process them?</a></li>
<li><a class="reference internal" href="#can-i-execute-a-task-by-name" id="id34">Can I execute a task by name?</a></li>
<li><a class="reference internal" href="#how-can-i-get-the-task-id-of-the-current-task" id="id35">How can I get the task id of the current task?</a></li>
<li><a class="reference internal" href="#can-i-specify-a-custom-task-id" id="id36">Can I specify a custom task_id?</a></li>
<li><a class="reference internal" href="#can-i-use-decorators-with-tasks" id="id37">Can I use decorators with tasks?</a></li>
<li><a class="reference internal" href="#can-i-use-natural-task-ids" id="id38">Can I use natural task ids?</a></li>
<li><a class="reference internal" href="#how-can-i-run-a-task-once-another-task-has-finished" id="id39">How can I run a task once another task has finished?</a></li>
<li><a class="reference internal" href="#can-i-cancel-the-execution-of-a-task" id="id40">Can I cancel the execution of a task?</a></li>
<li><a class="reference internal" href="#why-aren-t-my-remote-control-commands-received-by-all-workers" id="id41">Why aren’t my remote control commands received by all workers?</a></li>
<li><a class="reference internal" href="#can-i-send-some-tasks-to-only-some-servers" id="id42">Can I send some tasks to only some servers?</a></li>
<li><a class="reference internal" href="#can-i-change-the-interval-of-a-periodic-task-at-runtime" id="id43">Can I change the interval of a periodic task at runtime?</a></li>
<li><a class="reference internal" href="#does-celery-support-task-priorities" id="id44">Does celery support task priorities?</a></li>
<li><a class="reference internal" href="#should-i-use-retry-or-acks-late" id="id45">Should I use retry or acks_late?</a></li>
<li><a class="reference internal" href="#module-celery.task.base" id="id46">Can I schedule tasks to execute at a specific time?</a></li>
<li><a class="reference internal" href="#how-do-i-shut-down-celeryd-safely" id="id47">How do I shut down <cite>celeryd</cite> safely?</a></li>
<li><a class="reference internal" href="#how-do-i-run-celeryd-in-the-background-on-platform" id="id48">How do I run celeryd in the background on [platform]?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#django" id="id49">Django</a><ul>
<li><a class="reference internal" href="#what-purpose-does-the-database-tables-created-by-django-celery-have" id="id50">What purpose does the database tables created by django-celery have?</a></li>
</ul>
</li>
<li><a class="reference internal" href="#windows" id="id51">Windows</a><ul>
<li><a class="reference internal" href="#celeryd-keeps-spawning-processes-at-startup" id="id52">celeryd keeps spawning processes at startup</a></li>
<li><a class="reference internal" href="#the-b-beat-option-to-celeryd-doesn-t-work" id="id53">The <cite>-B</cite> / <cite>–beat</cite> option to celeryd doesn’t work?</a></li>
<li><a class="reference internal" href="#django-celery-can-t-find-settings" id="id54"><cite>django-celery</cite> can’t find settings?</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="general">
<span id="faq-general"></span><h2><a class="toc-backref" href="#id1">General</a><a class="headerlink" href="#general" title="Permalink to this headline">¶</a></h2>
<div class="section" id="what-kinds-of-things-should-i-use-celery-for">
<span id="faq-when-to-use"></span><h3><a class="toc-backref" href="#id2">What kinds of things should I use Celery for?</a><a class="headerlink" href="#what-kinds-of-things-should-i-use-celery-for" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> <a class="reference external" href="http://decafbad.com/blog/2008/07/04/queue-everything-and-delight-everyone">Queue everything and delight everyone</a> is a good article
describing why you would use a queue in a web context.</p>
<p>These are some common use cases:</p>
<ul class="simple">
<li>Running something in the background. For example, to finish the web request
as soon as possible, then update the users page incrementally.
This gives the user the impression of good performance and “snappiness”, even
though the real work might actually take some time.</li>
<li>Running something after the web request has finished.</li>
<li>Making sure something is done, by executing it asynchronously and using
retries.</li>
<li>Scheduling periodic work.</li>
</ul>
<p>And to some degree:</p>
<ul class="simple">
<li>Distributed computing.</li>
<li>Parallel execution.</li>
</ul>
</div>
</div>
<div class="section" id="misconceptions">
<span id="faq-misconceptions"></span><h2><a class="toc-backref" href="#id3">Misconceptions</a><a class="headerlink" href="#misconceptions" title="Permalink to this headline">¶</a></h2>
<div class="section" id="is-celery-dependent-on-pickle">
<span id="faq-serializion-is-a-choice"></span><h3><a class="toc-backref" href="#id4">Is Celery dependent on pickle?</a><a class="headerlink" href="#is-celery-dependent-on-pickle" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> No.</p>
<p>Celery can support any serialization scheme and has built-in support for
JSON, YAML, Pickle and msgpack. Also, as every task is associated with a
content type, you can even send one task using pickle, and another using JSON.</p>
<p>The default serialization format is pickle simply because it is
convenient (it supports sending complex Python objects as task arguments).</p>
<p>If you need to communicate with other languages you should change
to a serialization format that is suitable for that.</p>
<p>You can set a global default serializer, the default serializer for a
particular Task, or even what serializer to use when sending a single task
instance.</p>
</div>
<div class="section" id="is-celery-for-django-only">
<span id="faq-is-celery-for-django-only"></span><h3><a class="toc-backref" href="#id5">Is Celery for Django only?</a><a class="headerlink" href="#is-celery-for-django-only" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> No.</p>
<p>Celery does not depend on Django anymore. To use Celery with Django you have
to use the <a class="reference external" href="http://pypi.python.org/pypi/django-celery">django-celery</a> package.</p>
</div>
<div class="section" id="do-i-have-to-use-amqp-rabbitmq">
<span id="faq-is-celery-for-rabbitmq-only"></span><h3><a class="toc-backref" href="#id6">Do I have to use AMQP/RabbitMQ?</a><a class="headerlink" href="#do-i-have-to-use-amqp-rabbitmq" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: No.</p>
<p>You can also use Redis, Beanstalk, CouchDB, MongoDB or an SQL database,
see <a class="reference external" href="http://ask.github.com/celery/tutorials/otherqueues.html">Using other queues</a>.</p>
<p>These “virtual transports” may have limited broadcast and event functionality.
For example remote control commands only works with AMQP and Redis.</p>
<p>Redis or a database won’t perform as well as
an AMQP broker. If you have strict reliability requirements you are
encouraged to use RabbitMQ or another AMQP broker. Redis/database also use
polling, so they are likely to consume more resources. However, if you for
some reason are not able to use AMQP, feel free to use these alternatives.
They will probably work fine for most use cases, and note that the above
points are not specific to Celery; If using Redis/database as a queue worked
fine for you before, it probably will now. You can always upgrade later
if you need to.</p>
</div>
<div class="section" id="is-celery-multilingual">
<span id="faq-is-celery-multilingual"></span><h3><a class="toc-backref" href="#id7">Is Celery multilingual?</a><a class="headerlink" href="#is-celery-multilingual" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> Yes.</p>
<p><a class="reference internal" href="reference/celery.bin.celeryd.html#module-celery.bin.celeryd" title="celery.bin.celeryd"><tt class="xref py py-mod docutils literal"><span class="pre">celeryd</span></tt></a> is an implementation of Celery in Python. If the
language has an AMQP client, there shouldn’t be much work to create a worker
in your language. A Celery worker is just a program connecting to the broker
to process messages.</p>
<p>Also, there’s another way to be language independent, and that is to use REST
tasks, instead of your tasks being functions, they’re URLs. With this
information you can even create simple web servers that enable preloading of
code. See: <a class="reference external" href="http://ask.github.com/celery/userguide/remote-tasks.html">User Guide: Remote Tasks</a>.</p>
</div>
</div>
<div class="section" id="troubleshooting">
<span id="faq-troubleshooting"></span><h2><a class="toc-backref" href="#id8">Troubleshooting</a><a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h2>
<div class="section" id="mysql-is-throwing-deadlock-errors-what-can-i-do">
<span id="faq-mysql-deadlocks"></span><h3><a class="toc-backref" href="#id9">MySQL is throwing deadlock errors, what can I do?</a><a class="headerlink" href="#mysql-is-throwing-deadlock-errors-what-can-i-do" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> MySQL has default isolation level set to <cite>REPEATABLE-READ</cite>,
if you don’t really need that, set it to <cite>READ-COMMITTED</cite>.
You can do that by adding the following to your <tt class="file docutils literal"><span class="pre">my.cnf</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">mysqld</span><span class="p">]</span>
<span class="n">transaction</span><span class="o">-</span><span class="n">isolation</span> <span class="o">=</span> <span class="n">READ</span><span class="o">-</span><span class="n">COMMITTED</span>
</pre></div>
</div>
<p>For more information about InnoDB`s transaction model see <a class="reference external" href="http://dev.mysql.com/doc/refman/5.1/en/innodb-transaction-model.html">MySQL - The InnoDB
Transaction Model and Locking</a> in the MySQL user manual.</p>
<p>(Thanks to Honza Kral and Anton Tsigularov for this solution)</p>
</div>
<div class="section" id="celeryd-is-not-doing-anything-just-hanging">
<span id="faq-worker-hanging"></span><h3><a class="toc-backref" href="#id10">celeryd is not doing anything, just hanging</a><a class="headerlink" href="#celeryd-is-not-doing-anything-just-hanging" title="Permalink to this headline">¶</a></h3>
<dl class="docutils">
<dt><strong>Answer:</strong> See <a class="reference internal" href="#mysql-is-throwing-deadlock-errors-what-can-i-do">MySQL is throwing deadlock errors, what can I do?</a>.</dt>
<dd>or <cite>Why is Task.delay/apply* just hanging?</cite>.</dd>
</dl>
</div>
<div class="section" id="task-results-aren-t-reliably-returning">
<span id="faq-results-unreliable"></span><h3><a class="toc-backref" href="#id11">Task results aren’t reliably returning</a><a class="headerlink" href="#task-results-aren-t-reliably-returning" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> If you’re using the database backend for results, and in particular
using MySQL, see <a class="reference internal" href="#mysql-is-throwing-deadlock-errors-what-can-i-do">MySQL is throwing deadlock errors, what can I do?</a>.</p>
</div>
<div class="section" id="why-is-task-delay-apply-celeryd-just-hanging">
<span id="faq-publish-hanging"></span><h3><a class="toc-backref" href="#id12">Why is Task.delay/apply*/celeryd just hanging?</a><a class="headerlink" href="#why-is-task-delay-apply-celeryd-just-hanging" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> There is a bug in some AMQP clients that will make it hang if
it’s not able to authenticate the current user, the password doesn’t match or
the user does not have access to the virtual host specified. Be sure to check
your broker logs (for RabbitMQ that is <tt class="file docutils literal"><span class="pre">/var/log/rabbitmq/rabbit.log</span></tt> on
most systems), it usually contains a message describing the reason.</p>
</div>
<div class="section" id="does-it-work-on-freebsd">
<span id="faq-celeryd-on-freebsd"></span><h3><a class="toc-backref" href="#id13">Does it work on FreeBSD?</a><a class="headerlink" href="#does-it-work-on-freebsd" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> The multiprocessing pool requires a working POSIX semaphore
implementation which isn’t enabled in FreeBSD by default. You have to enable
POSIX semaphores in the kernel and manually recompile multiprocessing.</p>
<p>Luckily, Viktor Petersson has written a tutorial to get you started with
Celery on FreeBSD here:
<a class="reference external" href="http://www.playingwithwire.com/2009/10/how-to-get-celeryd-to-work-on-freebsd/">http://www.playingwithwire.com/2009/10/how-to-get-celeryd-to-work-on-freebsd/</a></p>
</div>
<div class="section" id="i-m-having-integrityerror-duplicate-key-errors-why">
<span id="faq-duplicate-key-errors"></span><h3><a class="toc-backref" href="#id14">I’m having <cite>IntegrityError: Duplicate Key</cite> errors. Why?</a><a class="headerlink" href="#i-m-having-integrityerror-duplicate-key-errors-why" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> See <a class="reference internal" href="#mysql-is-throwing-deadlock-errors-what-can-i-do">MySQL is throwing deadlock errors, what can I do?</a>.
Thanks to howsthedotcom.</p>
</div>
<div class="section" id="why-aren-t-my-tasks-processed">
<span id="faq-worker-stops-processing"></span><h3><a class="toc-backref" href="#id15">Why aren’t my tasks processed?</a><a class="headerlink" href="#why-aren-t-my-tasks-processed" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> With RabbitMQ you can see how many consumers are currently
receiving tasks by running the following command:</p>
<div class="highlight-python"><pre>$ rabbitmqctl list_queues -p <myvhost> name messages consumers
Listing queues ...
celery 2891 2</pre>
</div>
<p>This shows that there’s 2891 messages waiting to be processed in the task
queue, and there are two consumers processing them.</p>
<p>One reason that the queue is never emptied could be that you have a stale
worker process taking the messages hostage. This could happen if celeryd
wasn’t properly shut down.</p>
<p>When a message is received by a worker the broker waits for it to be
acknowledged before marking the message as processed. The broker will not
re-send that message to another consumer until the consumer is shut down
properly.</p>
<p>If you hit this problem you have to kill all workers manually and restart
them:</p>
<div class="highlight-python"><pre>ps auxww | grep celeryd | awk '{print $2}' | xargs kill</pre>
</div>
<p>You might have to wait a while until all workers have finished the work they’re
doing. If it’s still hanging after a long time you can kill them by force
with:</p>
<div class="highlight-python"><pre>ps auxww | grep celeryd | awk '{print $2}' | xargs kill -9</pre>
</div>
</div>
<div class="section" id="why-won-t-my-task-run">
<span id="faq-task-does-not-run"></span><h3><a class="toc-backref" href="#id16">Why won’t my Task run?</a><a class="headerlink" href="#why-won-t-my-task-run" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> There might be syntax errors preventing the tasks module being imported.</p>
<p>You can find out if Celery is able to run the task by executing the
task manually:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">myapp.tasks</span> <span class="kn">import</span> <span class="n">MyPeriodicTask</span>
<span class="gp">>>> </span><span class="n">MyPeriodicTask</span><span class="o">.</span><span class="n">delay</span><span class="p">()</span>
</pre></div>
</div>
<p>Watch celeryd`s log file to see if it’s able to find the task, or if some
other error is happening.</p>
</div>
<div class="section" id="why-won-t-my-periodic-task-run">
<span id="faq-periodic-task-does-not-run"></span><h3><a class="toc-backref" href="#id17">Why won’t my periodic task run?</a><a class="headerlink" href="#why-won-t-my-periodic-task-run" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> See <a class="reference internal" href="#why-won-t-my-task-run">Why won’t my Task run?</a>.</p>
</div>
<div class="section" id="how-do-i-discard-all-waiting-tasks">
<span id="faq-purge-the-queue"></span><h3><a class="toc-backref" href="#id18">How do I discard all waiting tasks?</a><a class="headerlink" href="#how-do-i-discard-all-waiting-tasks" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> You can use celeryctl to purge all configured task queues:</p>
<div class="highlight-python"><pre>$ celeryctl purge</pre>
</div>
<p>or programatically:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">celery.task.control</span> <span class="kn">import</span> <span class="n">discard_all</span>
<span class="gp">>>> </span><span class="n">discard_all</span><span class="p">()</span>
<span class="go">1753</span>
</pre></div>
</div>
<p>If you only want to purge messages from a specific queue
you have to use the AMQP API or the <strong class="program">camqadm</strong> utility:</p>
<div class="highlight-python"><pre>$ camqadm queue.purge <queue name></pre>
</div>
<p>The number 1753 is the number of messages deleted.</p>
<p>You can also start <a class="reference internal" href="reference/celery.bin.celeryd.html#module-celery.bin.celeryd" title="celery.bin.celeryd"><tt class="xref py py-mod docutils literal"><span class="pre">celeryd</span></tt></a> with the
<em class="xref std std-option">--purge</em> argument, to purge messages when the worker starts.</p>
</div>
<div class="section" id="i-ve-discarded-messages-but-there-are-still-messages-left-in-the-queue">
<span id="faq-messages-left-after-purge"></span><h3><a class="toc-backref" href="#id19">I’ve discarded messages, but there are still messages left in the queue?</a><a class="headerlink" href="#i-ve-discarded-messages-but-there-are-still-messages-left-in-the-queue" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> Tasks are acknowledged (removed from the queue) as soon
as they are actually executed. After the worker has received a task, it will
take some time until it is actually executed, especially if there are a lot
of tasks already waiting for execution. Messages that are not acknowledged are
held on to by the worker until it closes the connection to the broker (AMQP
server). When that connection is closed (e.g. because the worker was stopped)
the tasks will be re-sent by the broker to the next available worker (or the
same worker when it has been restarted), so to properly purge the queue of
waiting tasks you have to stop all the workers, and then discard the tasks
using <tt class="xref py py-func docutils literal"><span class="pre">discard_all()</span></tt>.</p>
</div>
</div>
<div class="section" id="results">
<span id="faq-results"></span><h2><a class="toc-backref" href="#id20">Results</a><a class="headerlink" href="#results" title="Permalink to this headline">¶</a></h2>
<div class="section" id="how-do-i-get-the-result-of-a-task-if-i-have-the-id-that-points-there">
<span id="faq-get-result-by-task-id"></span><h3><a class="toc-backref" href="#id21">How do I get the result of a task if I have the ID that points there?</a><a class="headerlink" href="#how-do-i-get-the-result-of-a-task-if-i-have-the-id-that-points-there" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Use <cite>Task.AsyncResult</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">MyTask</span><span class="o">.</span><span class="n">AsyncResult</span><span class="p">(</span><span class="n">task_id</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</pre></div>
</div>
<p>This will give you a <a class="reference internal" href="reference/celery.result.html#celery.result.BaseAsyncResult" title="celery.result.BaseAsyncResult"><tt class="xref py py-class docutils literal"><span class="pre">BaseAsyncResult</span></tt></a> instance
using the tasks current result backend.</p>
<p>If you need to specify a custom result backend you should use
<a class="reference internal" href="reference/celery.result.html#celery.result.BaseAsyncResult" title="celery.result.BaseAsyncResult"><tt class="xref py py-class docutils literal"><span class="pre">celery.result.BaseAsyncResult</span></tt></a> directly:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">celery.result</span> <span class="kn">import</span> <span class="n">BaseAsyncResult</span>
<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">BaseAsyncResult</span><span class="p">(</span><span class="n">task_id</span><span class="p">,</span> <span class="n">backend</span><span class="o">=...</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="security">
<span id="faq-security"></span><h2><a class="toc-backref" href="#id22">Security</a><a class="headerlink" href="#security" title="Permalink to this headline">¶</a></h2>
<div class="section" id="isn-t-using-pickle-a-security-concern">
<h3><a class="toc-backref" href="#id23">Isn’t using <cite>pickle</cite> a security concern?</a><a class="headerlink" href="#isn-t-using-pickle-a-security-concern" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes, indeed it is.</p>
<p>You are right to have a security concern, as this can indeed be a real issue.
It is essential that you protect against unauthorized
access to your broker, databases and other services transmitting pickled
data.</p>
<p>For the task messages you can set the <a class="reference internal" href="configuration.html#std:setting-CELERY_TASK_SERIALIZER"><tt class="xref std std-setting docutils literal"><span class="pre">CELERY_TASK_SERIALIZER</span></tt></a>
setting to “json” or “yaml” instead of pickle. There is
currently no alternative solution for task results (but writing a
custom result backend using JSON is a simple task)</p>
<p>Note that this is not just something you should be aware of with Celery, for
example also Django uses pickle for its cache client.</p>
</div>
<div class="section" id="can-messages-be-encrypted">
<h3><a class="toc-backref" href="#id24">Can messages be encrypted?</a><a class="headerlink" href="#can-messages-be-encrypted" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Some AMQP brokers supports using SSL (including RabbitMQ).
You can enable this using the <a class="reference internal" href="configuration.html#std:setting-BROKER_USE_SSL"><tt class="xref std std-setting docutils literal"><span class="pre">BROKER_USE_SSL</span></tt></a> setting.</p>
<p>It is also possible to add additional encryption and security to messages,
if you have a need for this then you should contact the <a class="reference internal" href="getting-started/resources.html#mailing-list"><em>Mailing list</em></a>.</p>
</div>
<div class="section" id="is-it-safe-to-run-celeryd-as-root">
<h3><a class="toc-backref" href="#id25">Is it safe to run <strong class="program">celeryd</strong> as root?</a><a class="headerlink" href="#is-it-safe-to-run-celeryd-as-root" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: No!</p>
<p>We’re not currently aware of any security issues, but it would
be incredibly naive to assume that they don’t exist, so running
the Celery services (<strong class="program">celeryd</strong>, <strong class="program">celerybeat</strong>,
<strong class="program">celeryev</strong>, etc) as an unprivileged user is recommended.</p>
</div>
</div>
<div class="section" id="brokers">
<span id="faq-brokers"></span><h2><a class="toc-backref" href="#id26">Brokers</a><a class="headerlink" href="#brokers" title="Permalink to this headline">¶</a></h2>
<div class="section" id="why-is-rabbitmq-crashing">
<h3><a class="toc-backref" href="#id27">Why is RabbitMQ crashing?</a><a class="headerlink" href="#why-is-rabbitmq-crashing" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> RabbitMQ will crash if it runs out of memory. This will be fixed in a
future release of RabbitMQ. please refer to the RabbitMQ FAQ:
<a class="reference external" href="http://www.rabbitmq.com/faq.html#node-runs-out-of-memory">http://www.rabbitmq.com/faq.html#node-runs-out-of-memory</a></p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>This is no longer the case, RabbitMQ versions 2.0 and above
includes a new persister, that is tolerant to out of memory
errors. RabbitMQ 2.1 or higher is recommended for Celery.</p>
<p class="last">If you’re still running an older version of RabbitMQ and experience
crashes, then please upgrade!</p>
</div>
<p>Misconfiguration of Celery can eventually lead to a crash
on older version of RabbitMQ. Even if it doesn’t crash, this
can still consume a lot of resources, so it is very
important that you are aware of the common pitfalls.</p>
<ul class="simple">
<li>Events.</li>
</ul>
<p>Running <a class="reference internal" href="reference/celery.bin.celeryd.html#module-celery.bin.celeryd" title="celery.bin.celeryd"><tt class="xref py py-mod docutils literal"><span class="pre">celeryd</span></tt></a> with the <em class="xref std std-option">-E</em>/<em class="xref std std-option">--events</em>
option will send messages for events happening inside of the worker.</p>
<p>Events should only be enabled if you have an active monitor consuming them,
or if you purge the event queue periodically.</p>
<ul class="simple">
<li>AMQP backend results.</li>
</ul>
<p>When running with the AMQP result backend, every task result will be sent
as a message. If you don’t collect these results, they will build up and
RabbitMQ will eventually run out of memory.</p>
<p>Results expire after 1 day by default. It may be a good idea
to lower this value by configuring the <a class="reference internal" href="configuration.html#std:setting-CELERY_TASK_RESULT_EXPIRES"><tt class="xref std std-setting docutils literal"><span class="pre">CELERY_TASK_RESULT_EXPIRES</span></tt></a>
setting.</p>
<p>If you don’t use the results for a task, make sure you set the
<cite>ignore_result</cite> option:</p>
</div>
<div class="section" id="can-i-use-celery-with-activemq-stomp">
<span id="faq-use-celery-with-stomp"></span><h3><a class="toc-backref" href="#id28">Can I use Celery with ActiveMQ/STOMP?</a><a class="headerlink" href="#can-i-use-celery-with-activemq-stomp" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: No. It used to be supported by Carrot,
but is not currently supported in Kombu.</p>
</div>
<div class="section" id="what-features-are-not-supported-when-not-using-an-amqp-broker">
<span id="faq-non-amqp-missing-features"></span><h3><a class="toc-backref" href="#id29">What features are not supported when not using an AMQP broker?</a><a class="headerlink" href="#what-features-are-not-supported-when-not-using-an-amqp-broker" title="Permalink to this headline">¶</a></h3>
<p>This is an incomplete list of features not available when
using the virtual transports:</p>
<blockquote>
<div><ul>
<li><p class="first">Remote control commands (supported only by Redis).</p>
</li>
<li><p class="first">Monitoring with events may not work in all virtual transports.</p>
</li>
<li><dl class="first docutils">
<dt>The <cite>header</cite> and <cite>fanout</cite> exchange types</dt>
<dd><p class="first last">(<cite>fanout</cite> is supported by Redis).</p>
</dd>
</dl>
</li>
</ul>
</div></blockquote>
</div>
</div>
<div class="section" id="tasks">
<span id="faq-tasks"></span><h2><a class="toc-backref" href="#id30">Tasks</a><a class="headerlink" href="#tasks" title="Permalink to this headline">¶</a></h2>
<div class="section" id="how-can-i-reuse-the-same-connection-when-applying-tasks">
<span id="faq-tasks-connection-reuse"></span><h3><a class="toc-backref" href="#id31">How can I reuse the same connection when applying tasks?</a><a class="headerlink" href="#how-can-i-reuse-the-same-connection-when-applying-tasks" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: See the <a class="reference internal" href="configuration.html#std:setting-BROKER_POOL_LIMIT"><tt class="xref std std-setting docutils literal"><span class="pre">BROKER_POOL_LIMIT</span></tt></a> setting.
The connection pool is enabled by default since version 2.5.</p>
</div>
<div class="section" id="sudo-in-a-subprocess-returns-none">
<span id="faq-sudo-subprocess"></span><h3><a class="toc-backref" href="#id32">Sudo in a <a class="reference external" href="http://docs.python.org/library/subprocess.html#subprocess" title="(in Python v2.7)"><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> returns <tt class="xref py py-const docutils literal"><span class="pre">None</span></tt></a><a class="headerlink" href="#sudo-in-a-subprocess-returns-none" title="Permalink to this headline">¶</a></h3>
<p>There is a sudo configuration option that makes it illegal for process
without a tty to run sudo:</p>
<div class="highlight-python"><pre>Defaults requiretty</pre>
</div>
<p>If you have this configuration in your <tt class="file docutils literal"><span class="pre">/etc/sudoers</span></tt> file then
tasks will not be able to call sudo when celeryd is running as a daemon.
If you want to enable that, then you need to remove the line from sudoers.</p>
<p>See: <a class="reference external" href="http://timelordz.com/wiki/Apache_Sudo_Commands">http://timelordz.com/wiki/Apache_Sudo_Commands</a></p>
</div>
<div class="section" id="why-do-workers-delete-tasks-from-the-queue-if-they-are-unable-to-process-them">
<span id="faq-deletes-unknown-tasks"></span><h3><a class="toc-backref" href="#id33">Why do workers delete tasks from the queue if they are unable to process them?</a><a class="headerlink" href="#why-do-workers-delete-tasks-from-the-queue-if-they-are-unable-to-process-them" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>:</p>
<p>The worker discards unknown tasks, messages with encoding errors and messages
that doesn’t contain the proper fields (as per the task message protocol).</p>
<p>If it did not ack (delete) them, they would be redelivered again and again
causing a loop.</p>
<p>There has been talk about moving these messages to a dead-letter queue,
but that has not yet been implemented.</p>
</div>
<div class="section" id="can-i-execute-a-task-by-name">
<span id="faq-execute-task-by-name"></span><h3><a class="toc-backref" href="#id34">Can I execute a task by name?</a><a class="headerlink" href="#can-i-execute-a-task-by-name" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes. Use <tt class="xref py py-func docutils literal"><span class="pre">celery.execute.send_task()</span></tt>.
You can also execute a task by name from any language
that has an AMQP client.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">celery.execute</span> <span class="kn">import</span> <span class="n">send_task</span>
<span class="gp">>>> </span><span class="n">send_task</span><span class="p">(</span><span class="s">"tasks.add"</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{})</span>
<span class="go"><AsyncResult: 373550e8-b9a0-4666-bc61-ace01fa4f91d></span>
</pre></div>
</div>
</div>
<div class="section" id="how-can-i-get-the-task-id-of-the-current-task">
<span id="faq-get-current-task-id"></span><h3><a class="toc-backref" href="#id35">How can I get the task id of the current task?</a><a class="headerlink" href="#how-can-i-get-the-task-id-of-the-current-task" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: The current id and more is available in the task request:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@task</span>
<span class="k">def</span> <span class="nf">mytask</span><span class="p">():</span>
<span class="n">cache</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">mytask</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="s">"Running"</span><span class="p">)</span>
</pre></div>
</div>
<p>For more information see <a class="reference internal" href="userguide/tasks.html#task-request-info"><em>Context</em></a>.</p>
</div>
<div class="section" id="can-i-specify-a-custom-task-id">
<span id="faq-custom-task-ids"></span><h3><a class="toc-backref" href="#id36">Can I specify a custom task_id?</a><a class="headerlink" href="#can-i-specify-a-custom-task-id" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes. Use the <cite>task_id</cite> argument to <tt class="xref py py-meth docutils literal"><span class="pre">Task.apply_async()</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">task</span><span class="o">.</span><span class="n">apply_async</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">,</span> <span class="n">task_id</span><span class="o">=</span><span class="s">"..."</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="can-i-use-decorators-with-tasks">
<h3><a class="toc-backref" href="#id37">Can I use decorators with tasks?</a><a class="headerlink" href="#can-i-use-decorators-with-tasks" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes. But please see note at <a class="reference internal" href="userguide/tasks.html#tasks-decorating"><em>Decorating tasks</em></a>.</p>
</div>
<div class="section" id="can-i-use-natural-task-ids">
<span id="faq-natural-task-ids"></span><h3><a class="toc-backref" href="#id38">Can I use natural task ids?</a><a class="headerlink" href="#can-i-use-natural-task-ids" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes, but make sure it is unique, as the behavior
for two tasks existing with the same id is undefined.</p>
<p>The world will probably not explode, but at the worst
they can overwrite each others results.</p>
</div>
<div class="section" id="how-can-i-run-a-task-once-another-task-has-finished">
<span id="faq-task-callbacks"></span><h3><a class="toc-backref" href="#id39">How can I run a task once another task has finished?</a><a class="headerlink" href="#how-can-i-run-a-task-once-another-task-has-finished" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: You can safely launch a task inside a task.
Also, a common pattern is to use callback tasks:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@task</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span>
<span class="k">if</span> <span class="n">callback</span><span class="p">:</span>
<span class="n">subtask</span><span class="p">(</span><span class="n">callback</span><span class="p">)</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="k">return</span> <span class="n">result</span>
<span class="nd">@task</span><span class="p">(</span><span class="n">ignore_result</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">log_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">logger</span> <span class="o">=</span> <span class="n">log_result</span><span class="o">.</span><span class="n">get_logger</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">"log_result got: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="p">))</span>
</pre></div>
</div>
<p>Invocation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">add</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">log_result</span><span class="o">.</span><span class="n">subtask</span><span class="p">())</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="userguide/tasksets.html"><em>Sets of tasks, Subtasks and Callbacks</em></a> for more information.</p>
</div>
<div class="section" id="can-i-cancel-the-execution-of-a-task">
<span id="faq-cancel-task"></span><h3><a class="toc-backref" href="#id40">Can I cancel the execution of a task?</a><a class="headerlink" href="#can-i-cancel-the-execution-of-a-task" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes. Use <cite>result.revoke</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">add</span><span class="o">.</span><span class="n">apply_async</span><span class="p">(</span><span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="n">countdown</span><span class="o">=</span><span class="mi">120</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">result</span><span class="o">.</span><span class="n">revoke</span><span class="p">()</span>
</pre></div>
</div>
<p>or if you only have the task id:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">celery.task.control</span> <span class="kn">import</span> <span class="n">revoke</span>
<span class="gp">>>> </span><span class="n">revoke</span><span class="p">(</span><span class="n">task_id</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="why-aren-t-my-remote-control-commands-received-by-all-workers">
<span id="faq-node-not-receiving-broadcast-commands"></span><h3><a class="toc-backref" href="#id41">Why aren’t my remote control commands received by all workers?</a><a class="headerlink" href="#why-aren-t-my-remote-control-commands-received-by-all-workers" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: To receive broadcast remote control commands, every worker node
uses its host name to create a unique queue name to listen to,
so if you have more than one worker with the same host name, the
control commands will be received in round-robin between them.</p>
<p>To work around this you can explicitly set the host name for every worker
using the <em class="xref std std-option">--hostname</em> argument to <a class="reference internal" href="reference/celery.bin.celeryd.html#module-celery.bin.celeryd" title="celery.bin.celeryd"><tt class="xref py py-mod docutils literal"><span class="pre">celeryd</span></tt></a>:</p>
<div class="highlight-python"><pre>$ celeryd --hostname=$(hostname).1
$ celeryd --hostname=$(hostname).2</pre>
</div>
<p>etc., etc...</p>
</div>
<div class="section" id="can-i-send-some-tasks-to-only-some-servers">
<span id="faq-task-routing"></span><h3><a class="toc-backref" href="#id42">Can I send some tasks to only some servers?</a><a class="headerlink" href="#can-i-send-some-tasks-to-only-some-servers" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer:</strong> Yes. You can route tasks to an arbitrary server using AMQP,
and a worker can bind to as many queues as it wants.</p>
<p>See <a class="reference internal" href="userguide/routing.html"><em>Routing Tasks</em></a> for more information.</p>
</div>
<div class="section" id="can-i-change-the-interval-of-a-periodic-task-at-runtime">
<span id="faq-change-periodic-task-interval-at-runtime"></span><h3><a class="toc-backref" href="#id43">Can I change the interval of a periodic task at runtime?</a><a class="headerlink" href="#can-i-change-the-interval-of-a-periodic-task-at-runtime" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes. You can use the Django database scheduler, or you can
override <cite>PeriodicTask.is_due</cite> or turn <cite>PeriodicTask.run_every</cite> into a
property:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">MyPeriodic</span><span class="p">(</span><span class="n">PeriodicTask</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c"># ...</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">run_every</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">get_interval_from_database</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="does-celery-support-task-priorities">
<span id="faq-task-priorities"></span><h3><a class="toc-backref" href="#id44">Does celery support task priorities?</a><a class="headerlink" href="#does-celery-support-task-priorities" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: No. In theory, yes, as AMQP supports priorities. However
RabbitMQ doesn’t implement them yet.</p>
<p>The usual way to prioritize work in Celery, is to route high priority tasks
to different servers. In the real world this may actually work better than per message
priorities. You can use this in combination with rate limiting to achieve a
highly responsive system.</p>
</div>
<div class="section" id="should-i-use-retry-or-acks-late">
<span id="faq-acks-late-vs-retry"></span><h3><a class="toc-backref" href="#id45">Should I use retry or acks_late?</a><a class="headerlink" href="#should-i-use-retry-or-acks-late" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Depends. It’s not necessarily one or the other, you may want
to use both.</p>
<p><cite>Task.retry</cite> is used to retry tasks, notably for expected errors that
is catchable with the <cite>try:</cite> block. The AMQP transaction is not used
for these errors: <strong>if the task raises an exception it is still acknowledged!</strong>.</p>
<p>The <cite>acks_late</cite> setting would be used when you need the task to be
executed again if the worker (for some reason) crashes mid-execution.
It’s important to note that the worker is not known to crash, and if
it does it is usually an unrecoverable error that requires human
intervention (bug in the worker, or task code).</p>
<p>In an ideal world you could safely retry any task that has failed, but
this is rarely the case. Imagine the following task:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="nd">@task</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">process_upload</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">tmpfile</span><span class="p">):</span>
<span class="c"># Increment a file count stored in a database</span>
<span class="n">increment_file_counter</span><span class="p">()</span>
<span class="n">add_file_metadata_to_db</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">tmpfile</span><span class="p">)</span>
<span class="n">copy_file_to_destination</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">tmpfile</span><span class="p">)</span>
</pre></div>
</div>
<p>If this crashed in the middle of copying the file to its destination
the world would contain incomplete state. This is not a critical
scenario of course, but you can probably imagine something far more
sinister. So for ease of programming we have less reliability;
It’s a good default, users who require it and know what they
are doing can still enable acks_late (and in the future hopefully
use manual acknowledgement)</p>
<p>In addition <cite>Task.retry</cite> has features not available in AMQP
transactions: delay between retries, max retries, etc.</p>
<p>So use retry for Python errors, and if your task is idempotent
combine that with <cite>acks_late</cite> if that level of reliability
is required.</p>
</div>
<div class="section" id="module-celery.task.base">
<span id="can-i-schedule-tasks-to-execute-at-a-specific-time"></span><span id="faq-schedule-at-specific-time"></span><h3><a class="toc-backref" href="#id46">Can I schedule tasks to execute at a specific time?</a><a class="headerlink" href="#module-celery.task.base" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Yes. You can use the <cite>eta</cite> argument of <tt class="xref py py-meth docutils literal"><span class="pre">Task.apply_async()</span></tt>.</p>
<p>Or to schedule a periodic task at a specific time, use the
<a class="reference internal" href="reference/celery.schedules.html#celery.schedules.crontab" title="celery.schedules.crontab"><tt class="xref py py-class docutils literal"><span class="pre">celery.schedules.crontab</span></tt></a> schedule behavior:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">celery.schedules</span> <span class="kn">import</span> <span class="n">crontab</span>
<span class="kn">from</span> <span class="nn">celery.task</span> <span class="kn">import</span> <span class="n">periodic_task</span>
<span class="nd">@periodic_task</span><span class="p">(</span><span class="n">run_every</span><span class="o">=</span><span class="n">crontab</span><span class="p">(</span><span class="n">hour</span><span class="o">=</span><span class="mi">7</span><span class="p">,</span> <span class="n">minute</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">day_of_week</span><span class="o">=</span><span class="s">"mon"</span><span class="p">))</span>
<span class="k">def</span> <span class="nf">every_monday_morning</span><span class="p">():</span>
<span class="k">print</span><span class="p">(</span><span class="s">"This is run every Monday morning at 7:30"</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="how-do-i-shut-down-celeryd-safely">
<span id="faq-safe-worker-shutdown"></span><h3><a class="toc-backref" href="#id47">How do I shut down <cite>celeryd</cite> safely?</a><a class="headerlink" href="#how-do-i-shut-down-celeryd-safely" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Use the <tt class="xref std std-sig docutils literal"><span class="pre">TERM</span></tt> signal, and the worker will finish all currently
executing jobs and shut down as soon as possible. No tasks should be lost.</p>
<p>You should never stop <a class="reference internal" href="reference/celery.bin.celeryd.html#module-celery.bin.celeryd" title="celery.bin.celeryd"><tt class="xref py py-mod docutils literal"><span class="pre">celeryd</span></tt></a> with the <tt class="xref std std-sig docutils literal"><span class="pre">KILL</span></tt> signal
(<em class="xref std std-option">-9</em>), unless you’ve tried <tt class="xref std std-sig docutils literal"><span class="pre">TERM</span></tt> a few times and waited a few
minutes to let it get a chance to shut down. As if you do tasks may be
terminated mid-execution, and they will not be re-run unless you have the
<cite>acks_late</cite> option set (<cite>Task.acks_late</cite> / <a class="reference internal" href="configuration.html#std:setting-CELERY_ACKS_LATE"><tt class="xref std std-setting docutils literal"><span class="pre">CELERY_ACKS_LATE</span></tt></a>).</p>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="userguide/workers.html#worker-stopping"><em>Stopping the worker</em></a></p>
</div>
</div>
<div class="section" id="how-do-i-run-celeryd-in-the-background-on-platform">
<span id="faq-daemonizing"></span><h3><a class="toc-backref" href="#id48">How do I run celeryd in the background on [platform]?</a><a class="headerlink" href="#how-do-i-run-celeryd-in-the-background-on-platform" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: Please see <a class="reference internal" href="cookbook/daemonizing.html#daemonizing"><em>Running celeryd as a daemon</em></a>.</p>
</div>
</div>
<div class="section" id="django">
<span id="faq-django"></span><h2><a class="toc-backref" href="#id49">Django</a><a class="headerlink" href="#django" title="Permalink to this headline">¶</a></h2>
<div class="section" id="what-purpose-does-the-database-tables-created-by-django-celery-have">
<span id="faq-django-database-tables"></span><h3><a class="toc-backref" href="#id50">What purpose does the database tables created by django-celery have?</a><a class="headerlink" href="#what-purpose-does-the-database-tables-created-by-django-celery-have" title="Permalink to this headline">¶</a></h3>
<p>Several database tables are created by default, these relate to</p>
<ul>
<li><p class="first">Monitoring</p>
<blockquote>
<div><p>When you use the django-admin monitor, the cluster state is written
to the <tt class="docutils literal"><span class="pre">TaskState</span></tt> and <tt class="docutils literal"><span class="pre">WorkerState</span></tt> models.</p>
</div></blockquote>
</li>
<li><p class="first">Periodic tasks</p>
<blockquote>
<div><p>When the database-backed schedule is used the periodic task
schedule is taken from the <tt class="docutils literal"><span class="pre">PeriodicTask</span></tt> model, there are
also several other helper tables (<tt class="docutils literal"><span class="pre">IntervalSchedule</span></tt>,
<tt class="docutils literal"><span class="pre">CrontabSchedule</span></tt>, <tt class="docutils literal"><span class="pre">PeriodicTasks</span></tt>).</p>
</div></blockquote>
</li>
<li><p class="first">Task results</p>
<blockquote>
<div><p>The database result backend is enabled by default when using django-celery
(this is for historical reasons, and thus for backward compatibility).</p>
<p>The results are stored in the <tt class="docutils literal"><span class="pre">TaskMeta</span></tt> and <tt class="docutils literal"><span class="pre">TaskSetMeta</span></tt> models.
<em>these tables are not created if another result backend is configured</em>.</p>
</div></blockquote>
</li>
</ul>
</div>
</div>
<div class="section" id="windows">
<span id="faq-windows"></span><h2><a class="toc-backref" href="#id51">Windows</a><a class="headerlink" href="#windows" title="Permalink to this headline">¶</a></h2>
<div class="section" id="celeryd-keeps-spawning-processes-at-startup">
<span id="faq-windows-worker-spawn-loop"></span><h3><a class="toc-backref" href="#id52">celeryd keeps spawning processes at startup</a><a class="headerlink" href="#celeryd-keeps-spawning-processes-at-startup" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: This is a known issue on Windows.
You have to start celeryd with the command:</p>
<div class="highlight-python"><pre>$ python -m celeryd.bin.celeryd</pre>
</div>
<p>Any additional arguments can be appended to this command.</p>
<p>See <a class="reference external" href="http://bit.ly/bo9RSw">http://bit.ly/bo9RSw</a></p>
</div>
<div class="section" id="the-b-beat-option-to-celeryd-doesn-t-work">
<span id="faq-windows-worker-embedded-beat"></span><h3><a class="toc-backref" href="#id53">The <cite>-B</cite> / <cite>–beat</cite> option to celeryd doesn’t work?</a><a class="headerlink" href="#the-b-beat-option-to-celeryd-doesn-t-work" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: That’s right. Run <cite>celerybeat</cite> and <cite>celeryd</cite> as separate
services instead.</p>
</div>
<div class="section" id="django-celery-can-t-find-settings">
<span id="faq-windows-django-settings"></span><h3><a class="toc-backref" href="#id54"><cite>django-celery</cite> can’t find settings?</a><a class="headerlink" href="#django-celery-can-t-find-settings" title="Permalink to this headline">¶</a></h3>
<p><strong>Answer</strong>: You need to specify the <em class="xref std std-option">--settings</em> argument to
<strong class="program">manage.py</strong>:</p>
<div class="highlight-python"><pre>$ python manage.py celeryd start --settings=settings</pre>
</div>
<p>See <a class="reference external" href="http://bit.ly/bo9RSw">http://bit.ly/bo9RSw</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper"><p class="logo"><a href="index.html">
<img class="logo" src="http://cloud.github.com/downloads/ask/celery/celery_128.png" alt="Logo"/>
</a></p>
<h4>Previous topic</h4>
<p class="topless"><a href="tutorials/clickcounter.html"
title="previous chapter">Tutorial: Creating a click counter using Kombu and celery</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="whatsnew-2.5.html"
title="next chapter">What’s new in Celery 2.5</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/faq.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="whatsnew-2.5.html" title="What’s new in Celery 2.5"
>next</a> |</li>
<li class="right" >
<a href="tutorials/clickcounter.html" title="Tutorial: Creating a click counter using Kombu and celery"
>previous</a> |</li>
<li><a href="index.html">Celery 2.5.3 documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2009-2012, Ask Solem & Contributors.
</div>
</body>
</html>
|