# Python node hanging due to list appending ?

**URL:** <https://forum.knime.com/t/python-node-hanging-due-to-list-appending/9751>\
**Category:** Community Extensions\
**Tags:** scripting-extensions\
**Created:** [December 12, 2017, 9:55am UTC](https://forum.knime.com/t/python-node-hanging-due-to-list-appending/9751 "2017-12-12T09:55:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![l.thomas](https://forum-cdn.knime.com/user_avatar/forum.knime.com/l.thomas/32/355_2.png) [@l.thomas](https://forum.knime.com/u/l.thomas)\
**Post date:** [December 12, 2017, 9:55am UTC](https://forum.knime.com/t/python-node-hanging-due-to-list-appending/9751/1 "2017-12-12T09:55:45Z")

</div>

Hello,

I am regularly using Python nodes in my workflow for image processing. My routine is to store the image in lists and then use those lists as column for the Panda output table. It is maybe not the most efficient way but it has always been working nicely so far.&nbsp;

Recently I had a problem with a Python node hanging at 30%.&nbsp;This node is supposed to take an image and rotate/mirror it for template matching purpose. After several tests I realised that the script is not hanging if I comment one line at the end of the script that is appending the newly processed image, although the final size of the list is&nbsp;only 2 or 3 image in this case !

I found this post on stack overflow&nbsp;[https://stackoverflow.com/questions/2473783/is-there-a-way-to-circumvent-python-list-append-becoming-progressively-slower](https://stackoverflow.com/questions/2473783/is-there-a-way-to-circumvent-python-list-append-becoming-progressively-slower)&nbsp;related to issue with list appending, do you think that could be the problem here?&nbsp;

I am using Python 2.7.13, Knime 3.5.0 on windows 10.

I have attached the workflow, it is about the python node in the top branch. You need to give an image to the image reader node to test it.

Here the Python script&nbsp;:

`import pandas as pd
from KNIPImage import KNIPImage
from scipy.ndimage.interpolation import rotate
import numpy as np`

`Step = flow_variables['DegreeStep']`

`# If no rotation nor flip then input table = output table
if Step == 0 and not flow_variables['FlipVertical'] and not flow_variables['FlipHorizontal']:
    output_table = input_table.copy()`

`else : # Rotation or flip
    output_table = pd.DataFrame() # create a new data table for the output
    List_Template = [] # final list of template after rotation, mirorring...`

`    for Template in input_table['Image']: # read template from table and flip them if necessary
        # Read template images and add them to final template list
        Template = Template.array
        List_Template.append(Template)`

`        # Generate flipped templates and add to the final list
        # Must be done before the rotation
        if flow_variables['FlipVertical']:
            FlipLR = np.fliplr(Template)
            List_Template.append(FlipLR)`

`        if flow_variables['FlipHorizontal']:
            FlipUD = np.flipud(Template)
            List_Template.append(FlipUD)
        
    # Generate rotated templates
    if Step != 0 :
        print 'Do Rotation'
        
        for Template in List_Template:
            # rotate
            print 'Generate rotation for new template' 
            for angle in xrange(Step,360,Step):
                NewTemplate = rotate(Template,angle,reshape=True,mode='nearest')
                List_Template.append(NewTemplate) # THIS LINE MAKES THE SCRIPT HANG ! `

`                # Control
                print type(NewTemplate)
                print NewTemplate.dtype
                print NewTemplate.shape
                
    
    output_table['Template'] = [KNIPImage(template) for template in List_Template]`

` `

- [MatchRotateTemplate - Paralell.knwf](https://www.knime.com/sites/default/files/MatchRotateTemplate%20-%20Paralell.knwf)

---

<div class="post-metadata">

**Author:** ![l.thomas](https://forum-cdn.knime.com/user_avatar/forum.knime.com/l.thomas/32/355_2.png) [@l.thomas](https://forum.knime.com/u/l.thomas)\
**Post date:** [December 12, 2017, 3:08pm UTC](https://forum.knime.com/t/python-node-hanging-due-to-list-appending/9751/2 "2017-12-12T15:08:03Z")

</div>

Sorry I found the bug in the python script. In the last for loop I am appending to the list on which I am looping therefore creating an endless loop.

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [April 21, 2023, 9:28pm UTC](https://forum.knime.com/t/python-node-hanging-due-to-list-appending/9751/4 "2023-04-21T21:28:09Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
