IronPython scripts in TIBCO Spotfire® are executed as one transaction
Last updated:
6:12pm Aug 05, 2018

Summary

In the TIBCO® Spotfire environment, IronPython scripts are executed as a single transaction. Transaction processing is designed to maintain a consistent state, by ensuring that any operations carried out on the system that are interdependent are either all completed successfully or all canceled successfully. This will however affect the way that your scripts are processed and executed.

More Information

When you run an IronPython script in Spotfire, all methods are executed as one transaction.

This means that the following script:

import time
period = 25;
Document.Data.Tables["firstTable"].Refresh();
time.sleep(period);
Document.Data.Tables["secondTable"].Refresh();

 

...will be executed in the following manner:

First, while parsing through the script:

period = 25;
time.sleep(period);

 

Second, as the transaction gets pushed out:

Document.Data.Tables["firstTable"].Refresh();
Document.Data.Tables["secondTable"].Refresh();

 

So, the executions get collected and put in a stack, to be executed as a single transaction in the end. This gives some inherit limitations, for example in the use-case seen above, where the expected sleep doesn't happen between the two table refreshes but before both of them. In this script, the programmer probably wanted to give time for the first table to finish refreshing before starting the refresh of the second table.

Workaround

As a workaround for the specific use case mentioned above, you can make use of the DataManager service and the DataTableCollection.Refresh method to ensure that all dependencies are taken into account when refreshing. An example of such a script is shown below, where tables are added to the list in the sequence they are dependent to each other:

from Spotfire.Dxp.Data import DataManager
DM = Application.GetService(DataManager);
DM.Tables.Refresh([table1, table2, etc...]);

 

Note: The DataTableCollection.Refresh method only considers dependencies between regular data tables, but ignores dependencies for on-demand tables.

Applies to

TIBCO® Spotfire 5.0.X and below.

Feedback (1)

Hi,

I have tried to use this solution to refresh tables in a manner that Table2 got refreshed only after Table1 refresh has been done but doesn't work.

Seems that both refreshes are executed simultaneously which are what I don't want.

My question is: Is there any other way to refresh Table2 only if Table1 has been refreshed?

from System.Collections.Generic import List
from Spotfire.Dxp.Data import *
from Spotfire.Dxp.Data import DataManager
DM = Application.GetService(DataManager)

for row in dataTable.GetRows(markings.AsIndexSet(),cursor):
	value = cursor.CurrentValue
	if value <> str.Empty:
		markedata.Add(value)
		
	if cursor.CurrentValue != '(Empty)':
		Document.Properties["message"] = "Used"
	else:
		DM.Tables.Refresh([Table1, Table2])

 

Marcio Sergio 11:00am Apr. 12, 2018