Ver código fonte

userguide/executing: Use publisher instead of connection to send bulk tasks.

Ask Solem 14 anos atrás
pai
commit
508b48161c
1 arquivos alterados com 5 adições e 23 exclusões
  1. 5 23
      docs/userguide/executing.rst

+ 5 - 23
docs/userguide/executing.rst

@@ -122,39 +122,21 @@ establish the connection yourself and pass it to ``apply_async``:
 
 
 .. code-block:: python
 .. code-block:: python
 
 
-    from celery.messaging import establish_connection
-
     numbers = [(2, 2), (4, 4), (8, 8), (16, 16)]
     numbers = [(2, 2), (4, 4), (8, 8), (16, 16)]
 
 
     results = []
     results = []
-    connection = establish_connection()
+    publisher = add.get_publisher()
     try:
     try:
         for args in numbers:
         for args in numbers:
-            res = add.apply_async(args=args, connection=connection)
+            res = add.apply_async(args=args, publisher=publisher)
             results.append(res)
             results.append(res)
     finally:
     finally:
-        connection.close()
+        publisher.close()
+        publisher.connection.close()
 
 
     print([res.get() for res in results])
     print([res.get() for res in results])
 
 
 
 
-In Python 2.5 and above, you can use the ``with`` statement:
-
-.. code-block:: python
-
-    from __future__ import with_statement
-    from celery.messaging import establish_connection
-
-    numbers = [(2, 2), (4, 4), (8, 8), (16, 16)]
-
-    results = []
-    with establish_connection() as connection:
-        for args in numbers:
-            res = add.apply_async(args=args, connection=connection)
-            results.append(res)
-
-    print([res.get() for res in results])
-
 The connection timeout is the number of seconds to wait before we give up
 The connection timeout is the number of seconds to wait before we give up
 establishing the connection. You can set this with the ``connect_timeout``
 establishing the connection. You can set this with the ``connect_timeout``
 argument to ``apply_async``:
 argument to ``apply_async``:
@@ -167,7 +149,7 @@ Or if you handle the connection manually:
 
 
 .. code-block:: python
 .. code-block:: python
 
 
-    connection = establish_connection(connect_timeout=3)
+    publisher = add.get_publisher(connect_timeout=3)
 
 
 
 
 Routing options
 Routing options