Tags:
Forums: 

พอดี ไปอ่านใน http://celeryproject.org/

เค้ามีตัวอย่างง่าย

from celery.decorators import task

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

เข้าใจว่า เป็นการทำให้ add เป็น asynchronous task

การใช้คำสั้ง @task คือการประกาศอะไร หรือครับ แล้วมีวิธีการเขียนโค้ดอย่างไร
พอมีท่านใด ให้ความกระจ่างได้บ้างครับ

Get latest news from Blognone
By: nitipit
Android
on 27 November 2010 - 01:19 #235663

เป็นการใช้ Function Decorators ครับ
อธิบายเพิ่มเติมก็น่าจะหมายความว่า การตกแต่ง function (ให้มี parameter หรือ method อื่นๆ เพิ่มเข้ามา)

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

มีค่าเท่ากับการเขียนแบบนี้ครับ

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

add = task(add)