0

I have a object with a couple of methods. One method includes a bunch of nested if-statements, for which i want to return certain values. The method is called within a for loop in an external .py-file. Problem is, that the return values never arrive in the external file, so that i am not able to work with the returned value.

The for loop and therefore also the method call is within a celery task, because this i a long running task on a web application (flask)

tasks.py

@celery.task 
def LongRunningTask(foo, bar, ...):
    instance = Object(foo, bar, ...)

    list_containing_elems = [....]

    variable1 = 0
    variable2 = 0 

    for elem in list_containing_elems:
        instance.method(foo, variable1, variable2)
        print(f"Here should the returned {variable1} and {variable2} be displayed")

object.py


class Object():

    def __init__(self, ...):
        [...]

    def method(self, foo, variable1, variable2):

        [...]

        if statement1:
            [...]

            if statement2:
                [...]

                if statement3:
                     [...]
                     variable1 += 1
                     return variable1

                else:
                     [...]
                     variable2 += 1
                     return variable2
            else:
                [...]
        else:
            [...]

I would expect, that the returned (and incremented) variable will get passed to the tasks.py print statement - but that is not the case.

I'm really stucked,...maybe due to the warm wheather outside.

Does anyone mayhaps has an idea?

chickenshifu
  • 181
  • 5
  • 15

1 Answers1

0

In last line you are printing initial values of variable1 & variable2 You need to store the returned value in a variable : returnedValue = instance.method(foo, variable1, variable2) Then the variable (returnedValue) must be printed.

ibra
  • 390
  • 3
  • 13