title: Keep initialized variables after executing Celery task
body: <p>I have some code which is like this :</p>
  
  <pre><code>model = None
  
  @app.task()
  def compute_something():
      global model
      if model is None:
          # Initialize model
      # Use model to perform computation
  </code></pre>
  
  <p>So I want the set-up code (lengthy model initialization) to be executed only once when necessary, and further call to the same task could be reusing these initialized variable.</p>
  
  <p>I know it partly breaks the concept of tasks being strictly atomics. But by default this does not seem to work because (I assume) multiprocessing forks separate processes for each tasks, losing the initialization.</p>
  
  <p>Is there a way to achieve something like this?</p>
  
  <p>RELATED QUESTION:</p>
  
  <p>Another way to look at this, is there a way for a worker to look into the task queue and group tasks to perform them together more efficiently?</p>
  
  <p>Let's say a worker will be much more efficient processing a group of tasks at the same time, than doing them one after the other (GPU job for instance, or here loading a big parameter file into memory).</p>
  
  <p>I was wondering if there was a way for the worker to gather several instances of the same task in the task queue and process them in a batch way instead of one by one.</p>