2
Expensive,
When calling a python class, the variables of that class will always be restarted?
What happens is this: I’m working with the parallelization of my code. I receive the data returned from the database, break them into several Hunks and send Celery these Hunks, so that it processes and saves the results in a list. For this, I have a controller class that has two static methods. The first one must save the values it receives in a list. The second must take this list, order and return its first value. My class is the following:
class chunkControler:
value = []
@staticmethod
def setregisterpercent(registerpercent):
__class__.value.append(registerpercent)
@staticmethod
def getvalue():
__class__.value.sort()
return __class__.value[0]
To save the values, I call this class as follows in my task:
from .chunkControler import chunkControler
chunkControler.setregisterpercent(registerpercent)
and to recover the values, I do as follows in my view:
from .chunkControler import chunkControler
resultado = chunkControler.getvalue()
print(resultado)
(The Imports are being made at the beginning of tasks.py and views.py)
The problem is that when I call the method chunkControler.getvalue()
, the return is being from the empty list, as if a new list were created for this return. Is there any way to circumvent this and return the list that was initially created?
https://repl.it/repls/JampackedBriskCookies
– bfavaretto
Thanks for the reply, my program is with the same structure, but I continue to receive as return an empty list. I guess it must be some problem with Celery then.
– Willian Freitas
Maybe you’re trying to get the data ahead of time (since Celery is based on asynchrony)
– bfavaretto