0

I have written a celery chord like this:

current = raw_input("Please give the date in this format 'dd/mm/yyyy': ")
day,month,year = current.split('/')
date = datetime.date(int(year), int(month), int(day))
date1 = datetime.date(2014, 06, 17)
date = date.toordinal()
date1 = date1.toordinal()

callback = A.si((datetime.date.fromordinal(i)) for i in range(date,date1+1))
header = [B.si((datetime.date.fromordinal(i)) for i in range(date,date1+1))]
result = chord(header)(callback)
res = result.apply_async()
res.get()

Now i am having this error:

TypeError: object.__new__(generator) is not safe, use generator.__new__()

How could i write the callback and the header?????

Proloy
  • 343
  • 1
  • 3
  • 14

1 Answers1

0

I suspect it's happening because Celery is doing some serialization (with pickle by default, depending of your version) / copy of the arguments of a task, and since generators cannot be pickled or copied, it yields this error. You should try with a list (or a tuple):

dates = [datetime.date.fromordinal(i) for i in range(date, date1 + 1)]
callback = A.si(dates)
header = [B.si(dates)]
result = chord(header)(callback)
res = result.apply_async()
res.get()
Community
  • 1
  • 1
Seb D.
  • 5,046
  • 1
  • 28
  • 36
  • I use the list element you showed but it is giving this error now 'TypeError: descriptor 'strftime' requires a 'datetime.date' object but received a 'list'' – Proloy Jun 26 '14 at 14:06
  • That would be a mistake in your code inside your tasks, which has probably nothing to do with Celery. From the look of the error, you tried to apply `strftime` directly to the list `dates` instead of applying it to each of its values. – Seb D. Jun 26 '14 at 14:09