palantir-foundryfoundry-code-workbooks

Why are visualizations not appearing on the correct nodes in Code Workbook?


I have a code workbook in which I create several plots using Matplotib: enter image description here

If I run all downstream from my data-dataset the plots are not shown at the expected node, sometimes they do not contain any plots and sometimes some of the nodes contain more than one visualization.


Solution

  • This is happening because matplotlib is not thread safe. By adding @synchronous_node_execution to each of the plot_-code workbook nodes, you can lock each node to ensure the visualization is shown on the correct node:

    # plot 1 
    import matplotlib.pyplot as plt
    
    @synchronous_node_execution
    def plot_1(data):
        df = data
        [...]