Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting TypeError: 'Module' object is not callable on celery task decorator

Tags:

django

celery

Trying out celery for django I ran into a problem with @task decorator. This is running on Windows 7.

In my celerytest.tasks module I have the following code

from celery import task

@task
def add(x,y):
    return x + y

From the command prompt I run:

python manage.py shell

Trying to import my module from shell:

from celerytest.tasks import add

I get the following error:

>>> from celerytest.tasks import add
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "d:\...\celerytest\tasks.py", line 8, in <module>
   @task
TypeError: 'module' object is not callable

I tried googling this for a long time, but it seems I am the only one in the world with this problem.

like image 562
vedran Avatar asked Jun 02 '12 17:06

vedran


People also ask

How do I fix this error TypeError module object is not callable?

To fix this error, we need to change the import statement in “mycode.py” file and specify a specific function in our import statement. In the above code, we have imported “mymodule” function from “mymodule” module, so our compiler won't get confused and can execute the function mymodule().

What is TypeError module object is not callable?

The error “TypeError: 'module' object is not callable” occurs when the python compiler gets confused between function name and module name and try to run a module name as a function. In the above example, we have imported the module “os” and then try to run the same “os” module name as a function.

Are celery tasks asynchronous?

Once you integrate Celery into your app, you can send time-intensive tasks to Celery's task queue. That way, your web app can continue to respond quickly to users while Celery completes expensive operations asynchronously in the background.


1 Answers

Well, I was reading the documentation for 2.6.0 rc3, but installed 2.5.3.

http://ask.github.com/celery/django/first-steps-with-django.html

When using the import like this:

from celery.task import task

everything seems to work.

like image 180
vedran Avatar answered Oct 05 '22 19:10

vedran