How to set project variables inside process running on Thread?

Registered Posts: 2 ✭✭

Hi there,

I am trying to set some project variable using set_variable() method of Dataiku API. But it somehow only runs once. Below is my DASH webapp code snippet for reference -

import threading
import dataiku
import time

def start_execution_publish_to_pbi(config_id):
try:
project = dataiku.Project()
variables = project.get_variables()
variables['standard']['projection_publish_to_pbi_running_process'] = config_id
project.set_variables(variables)

time.sleep(10)


project = dataiku.Project() #Does not update the project variable
variables = project.get_variables()
variables['standard']['projection_publish_to_pbi_running_process'] = ''
project.set_variables(variables)
except Exception as e:

project = dataiku.Project()
variables = project.get_variables()
variables['standard']['projection_publish_to_pbi_running_process'] = ''
project.set_variables(variables) thread = threading.Thread(target=start_execution_publish_to_pbi, args=('101',))
thread.daemon = True # To ensure threads don't block app shutdown
thread.start()

Can some one please assist here why the set_variable() does not works second time?

P.S. - I am trying to implement a task queue which will not trigger the start_execution_publish_to_pbi() if there is already some process running.

Operating system used: Windows

Operating system used: Windows

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,363 Neuron

    What's the point of the Try/Except. Doesn't seem to make any sense to me. You trap the exception and do nothing with it. I would remove the Try/Except first and understand why is the code failing.

  • Registered Posts: 2 ✭✭

    The code is not throwing any exception. The set_variables(variables) called second time at the end of function does not update the Project Variables.

  • Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,363 Neuron

    I understand the code is not throwing any exceptions but that's because you are traping the exception with Try/Except and not even printing it. So remove the Try/Except and see whether the code really works or not. And if it doesn't what's the error.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.