python - Is it possible to return a list of a class in celery? -


i have question celery. calling function named task , want return list of specific class. if error on server:

no module named 'modelsgert' 

modelsgert name of python file class has been defined. have imported same file project located on server yet doesn't know this. sends reference file location of file on celery server.

code celery server:

from celery import celery sqlalchemy import create_engine sqlalchemy.orm import sessionmaker modelsgert import( diagnose, procedur, dbsession, data ) import time celery = celery('tasks', backend='amqp', broker='amqp://guest@localhost//')  @celery.task() def test_task(data):     diagnose = dbsession.query(diagnose)     listofdiagnoses = []     listofdiagnoses.append(diagnose[0])     listofdiagnoses.append(diagnose[1])     return (listofdiagnoses) 

code pyramid server

celery = celery( backend='amqp', broker='amqp://guest@192.168.1.5:5672//')     celery.conf.update(celery_result_backend = 'amqp', broker_host='192.168.1.5', broker_user='kristof', broker_password='bob', broker_vhost='myvhost', broker_port=5672)     task = celery.send_task('tasks.test_task',["kakker"])     thedata = task.get() 

is there way fix problem in proper way?

are modelsgert available when see error?

celery uses pickle default, , module indeed stores the name of module , class (together data contained in class), , when loading data again, module , class looked dynamically. stage fails because modelsgert cannot imported.

i must note trying send sqlalchemy objects here, , idea. objects tied specific session, , when unpickle objects session no longer there. moveover, objects represent database state, , database state have changed time load objects again.

you should, instead, send object identifiers, , query objects again on other side. instead of list of diagnose objects, send primary keys instead:

listofdiagnoses = [d.id d in diagnose] 

on other side, you'd use identifiers load diagnose objects again database.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -