elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Tutorial básico de Quickjs


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  Multiprocessing y MatPlotLib
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Multiprocessing y MatPlotLib  (Leído 2,762 veces)
Arhoc

Desconectado Desconectado

Mensajes: 27


Welcome home, root!


Ver Perfil WWW
Multiprocessing y MatPlotLib
« en: 22 Octubre 2022, 20:29 pm »

Holaaa, estuve intentando plottear asincronamente en dos subplots, empleando lo que sea, Threads, Multiprocessing.Process y Pools, ¿Que puedo hacer?
Por cierto, por cierto, al utilizar cualquiera de estos 3 me da error y no he podido emplearlos, mi codigo esta dividido en tres archivos, los cuales contienen:

MAIN.PY
Código
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import multiprocessing
  4. import lines
  5. import bars
  6.  
  7. if __name__ == "__main__":
  8.    fig, ax = plt.subplots(2, 2)
  9.  
  10.    with multiprocessing.get_context("spawn").Pool() as pool:
  11.        pool.map(lines.start, (plt, fig, ax[0, 0]))
  12.  
  13.    # Esto es de cuando intente utilizar SubProcesos
  14.    """barproc = multiprocessing.Process(target=bars.start, args=(plt, fig, ax[0, 1]))
  15.    procs.append(barproc)
  16.    barproc.start()
  17.  
  18.    for proc in procs:
  19.        proc.join()"""
  20.  
  21.  

LINES.PY
Código
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.animation as animation
  4.  
  5. import random
  6.  
  7.  
  8. def start(plt, fig, ax):
  9.    x = np.arange(0, 2*np.pi, 0.1)
  10.    line1, = ax.plot(x, np.sin(x))
  11.    line2, = ax.plot(x, np.sin(x))
  12.    line3, = ax.plot(x, np.sin(x))
  13.  
  14.    def animate(i):
  15.        line1.set_ydata(np.sin(x - i / 50))
  16.        line2.set_ydata(np.sin(x + i / 75))
  17.        line3.set_ydata(np.sin(x - i / 100))
  18.        return line1, line2, line3
  19.  
  20.    anim = animation.FuncAnimation(fig, animate, interval=1, blit=True, save_count=25)
  21.  
  22.    plt.show()
  23.  
  24. if __name__ == "__main__":
  25.    fig, ax = plt.subplots(2, 2)
  26.    start(plt, fig, ax[0, 0])
  27.  

BARS.PY: este es igual que el anterior pero usando graficas de barras :v

Y el error que me da es este:
Código
  1. Process SpawnPoolWorker-1:
  2. Traceback (most recent call last):
  3.  File "/usr/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
  4.    self.run()
  5.  File "/usr/lib/python3.10/multiprocessing/process.py", line 108, in run
  6.    self._target(*self._args, **self._kwargs)
  7.  File "/usr/lib/python3.10/multiprocessing/pool.py", line 114, in worker
  8.    task = get()
  9.  File "/usr/lib/python3.10/multiprocessing/queues.py", line 367, in get
  10.    return _ForkingPickler.loads(res)
  11.  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 2911, in __setstate__
  12.    mgr = plt._backend_mod.new_figure_manager_given_figure(num, self)
  13. AttributeError: 'NoneType' object has no attribute 'new_figure_manager_given_figure'
  14. Process SpawnPoolWorker-2:
  15. Traceback (most recent call last):
  16.  File "/usr/lib/python3.10/multiprocessing/process.py", line 314, in _bootstrap
  17.    self.run()
  18.  File "/usr/lib/python3.10/multiprocessing/process.py", line 108, in run
  19.    self._target(*self._args, **self._kwargs)
  20.  File "/usr/lib/python3.10/multiprocessing/pool.py", line 114, in worker
  21.    task = get()
  22.  File "/usr/lib/python3.10/multiprocessing/queues.py", line 367, in get
  23.    return _ForkingPickler.loads(res)
  24.  File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 2911, in __setstate__
  25.    mgr = plt._backend_mod.new_figure_manager_given_figure(num, self)
  26. AttributeError: 'NoneType' object has no attribute 'new_figure_manager_given_figure'
  27.  

Entonces, umm, ¿que podria hacer yo para plottear en dos o mas subplots asincronamente?


En línea

I am trapped in a TTY, this is the new home for mind, my root directory is still not mounting today.
reymosquito

Desconectado Desconectado

Mensajes: 81


Ver Perfil
Re: Multiprocessing y MatPlotLib
« Respuesta #1 en: 23 Octubre 2022, 00:30 am »

debo ser honesto y decir que la verdad nunca e usado with con multiprocess, por lo cual te muestro que cambiaría:

Código
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import multiprocessing
  4. from lines import start
  5. import bars
  6.  
  7. if __name__ == "__main__":
  8.    fig, ax = plt.subplots(2, 2)
  9.    context =multiprocessing.get_context("spawn")
  10.    proceso = context.Process(start(plt, fig, ax[0, 0] ))
  11.  


con eso ya debería funcionar y a partir de ahí las modificciones pertinentes con las funciones start y join


En línea

Arhoc

Desconectado Desconectado

Mensajes: 27


Welcome home, root!


Ver Perfil WWW
Re: Multiprocessing y MatPlotLib
« Respuesta #2 en: 23 Octubre 2022, 01:48 am »

Me anda, sin embargo no se realiza asincronamente, ¿hay algo mas que deba hacer?
En línea

I am trapped in a TTY, this is the new home for mind, my root directory is still not mounting today.
Arhoc

Desconectado Desconectado

Mensajes: 27


Welcome home, root!


Ver Perfil WWW
Re: Multiprocessing y MatPlotLib
« Respuesta #3 en: 23 Octubre 2022, 02:04 am »

debo ser honesto y decir que la verdad nunca e usado with con multiprocess, por lo cual te muestro que cambiaría:

Código
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import multiprocessing
  4. from lines import start
  5. import bars
  6.  
  7. if __name__ == "__main__":
  8.    fig, ax = plt.subplots(2, 2)
  9.    context =multiprocessing.get_context("spawn")
  10.    proceso = context.Process(start(plt, fig, ax[0, 0] ))
  11.  


con eso ya debería funcionar y a partir de ahí las modificciones pertinentes con las funciones start y join

perfecto, sin utilizar target y args no da asincronamente, pero usandolos da error:

Código
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import multiprocessing
  4. import lines
  5. import bars
  6.  
  7. if __name__ == "__main__":
  8.    fig, ax = plt.subplots(2, 2)
  9.  
  10.    context = multiprocessing.get_context("spawn")
  11.  
  12.    proc1 = context.Process(target=lines.start, args=(plt, fig, ax[0, 0]))
  13.    proc2 = context.Process(target=bars.start, args=(plt, fig, ax[1, 1]))
  14.  
  15.    proc1.start()
  16.    proc2.start()
  17.  
  18.  
En línea

I am trapped in a TTY, this is the new home for mind, my root directory is still not mounting today.
Arhoc

Desconectado Desconectado

Mensajes: 27


Welcome home, root!


Ver Perfil WWW
Re: Multiprocessing y MatPlotLib
« Respuesta #4 en: 23 Octubre 2022, 02:08 am »

perfecto, sin utilizar target y args no da asincronamente, pero usandolos da error:

Código
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import multiprocessing
  4. import lines
  5. import bars
  6.  
  7. if __name__ == "__main__":
  8.    fig, ax = plt.subplots(2, 2)
  9.  
  10.    context = multiprocessing.get_context("spawn")
  11.  
  12.    proc1 = context.Process(target=lines.start, args=(plt, fig, ax[0, 0]))
  13.    proc2 = context.Process(target=bars.start, args=(plt, fig, ax[1, 1]))
  14.  
  15.    proc1.start()
  16.    proc2.start()
  17.  
  18.  

ah no ese no era

Código
  1. Traceback (most recent call last):
  2.  File "/home/arhoc/scientistsimulator/main.py", line 15, in <module>
  3.    proc1.start()
  4.  File "/usr/lib/python3.10/multiprocessing/process.py", line 121, in start
  5.    self._popen = self._Popen(self)
  6.  File "/usr/lib/python3.10/multiprocessing/context.py", line 288, in _Popen
  7.    return Popen(process_obj)
  8.  File "/usr/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 32, in __init__
  9.    super().__init__(process_obj)
  10.  File "/usr/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
  11.    self._launch(process_obj)
  12.  File "/usr/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 47, in _launch
  13.    reduction.dump(process_obj, fp)
  14.  File "/usr/lib/python3.10/multiprocessing/reduction.py", line 60, in dump
  15.    ForkingPickler(file, protocol).dump(obj)
  16. TypeError: cannot pickle 'module' object
  17.  
En línea

I am trapped in a TTY, this is the new home for mind, my root directory is still not mounting today.
reymosquito

Desconectado Desconectado

Mensajes: 81


Ver Perfil
Re: Multiprocessing y MatPlotLib
« Respuesta #5 en: 24 Octubre 2022, 03:22 am »

ahora no estoy con posibilidad de mirarlo, mañana lo veo.
En línea

Arhoc

Desconectado Desconectado

Mensajes: 27


Welcome home, root!


Ver Perfil WWW
Re: Multiprocessing y MatPlotLib
« Respuesta #6 en: 24 Octubre 2022, 03:46 am »

Ya lo solucione, de hecho nisiquiera emplee programacion asincrona / concurrente
En línea

I am trapped in a TTY, this is the new home for mind, my root directory is still not mounting today.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema con libreria Matplotlib en Wifislax
Wireless en Linux
NEXUS978 0 1,999 Último mensaje 30 Octubre 2014, 19:51 pm
por NEXUS978
¿Como coger el PID de un proceso hijo que ha hecho Event.set()? | Python3 multiprocessing Event
Scripting
Drakaris 2 4,030 Último mensaje 6 Diciembre 2021, 20:10 pm
por Danielㅤ
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines