0

I have this 2 processes with a list created with manager.list() being shared between them, one is called DATA() and it is "generating" data and appending to the list and the other is plotting that data using Matplotlib animation FuncAnimation.

The issue I am having, is that once I pass the list to the animate function

[ani = FuncAnimation(plt.gcf(),animate,fargs= (List,), interval=1000)]

the function is receiving a <class 'int'> instead of a <class multiprocessing.managers.ListProxy' >.

Does anyone have any idea why this is happening?

import pandas as pd
import matplotlib.pyplot as plt
import multiprocessing as mp
from multiprocessing import freeze_support,Manager
import time
from matplotlib.animation import FuncAnimation
plt.style.use('fivethirtyeight')

my_c = ['x','y']
initial = [[1,3],[2,4],[3,8],[4,6],[5,8],[6,5],[6,2],[7,7]]
df = pd.DataFrame(columns=my_c)

def data(List):

    for i in initial:
        #every 1 sec the list created with the manager.list() is updated
        List.append(i)
        #print(f"list in loop {List}")#making sure list is not empty
        time.sleep(1)


def animate(List,i):

    print(f"list in animate {type(List)}")# prints <class 'int'> instead of  <class 'multiprocessing.managers.ListProxy'>
    global df
    for l in List:
        print(f" for loop: {type(l)}")
        df = df.append({'x':l[0],'y':l[1]}, ignore_index = True)
    plt.plot(df['x'],df['y'],label = "Price")
    plt.tight_layout()

def run(List):

    print(f"run funciton {type(List)}") # prints  <class 'multiprocessing.managers.ListProxy'>
    ani = FuncAnimation(plt.gcf(),animate,fargs= (List,), interval=1000) #passes List as an argument to Animate function
    plt.show()

if __name__ == '__main__':
    manager = mp.Manager()
    List  =  manager.list()
    freeze_support()
    p1 = mp.Process(target = run,args =(List,))
    p2 = mp.Process(target = data,args=(List,))
    p2.start()
    p1.start()
    p2.join()
    p1.join()

1 Answers1

0

Turns out the animate function was receiving 2 arguments. this response has a better explanation TypeError: method() takes 1 positional argument but 2 were given. I had to modify my function from def animate(List) to animate(self, List)