Python Forum
Non-blocking real-time plotting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Non-blocking real-time plotting
#6
You might want to try using a multiprocessing Manager list or dictionary. You can write to it in a process or processes, and can plot from it in another process. This is a simple program that uses a Manager list. It does not plot in real time, but the list creation and use is the same. One of the docs on the web https://pymotw.com/3/multiprocessing/

import random
import time
from multiprocessing import Process, Manager

def add_em(process_num, add_list, mgr_list):
    total=0
    for num in add_list:
         total += num

    mgr_list.append([process_num, total, add_list])

manager = Manager()
mgr_list = manager.list()

processes_list=[]
## start 10 processes
for ctr in range(10):
    ## how many numbers to add up
    length_nums=random.randint(2, 11)
    add_list=[]
    for num in range(length_nums):
        add_list.append(random.randint(1, 100))
    p=Process(target=add_em, args=(ctr, add_list, mgr_list))
    p.start()
    processes_list.append(p)

print("waiting for processes to finish")
for p in processes_list:
    if p.is_alive():
        print("     ", p.name, p.pid, p.is_alive())
        time.sleep(0.5)

print("\nAll processes finished")
import pprint
pprint.pprint(list(mgr_list)) 
Reply


Messages In This Thread
Non-blocking real-time plotting - by slow_rider - Jan-06-2023, 12:11 AM
RE: Non-blocking real-time plotting - by Larz60+ - Jan-06-2023, 09:02 PM
RE: Non-blocking real-time plotting - by deanhystad - Jan-07-2023, 07:47 AM
RE: Non-blocking real-time plotting - by deanhystad - Jan-07-2023, 07:09 PM
RE: Non-blocking real-time plotting - by woooee - Jan-07-2023, 09:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Why is this asyncio task blocking? SecureCoop 1 886 Jun-06-2023, 02:43 PM
Last Post: SecureCoop
  Plotting by Time, error mansoorahs 1 787 May-16-2023, 09:46 AM
Last Post: Larz60+
  Make code non-blocking? Extra 0 1,197 Dec-03-2022, 10:07 PM
Last Post: Extra
  Real time database satyanarayana 3 1,746 Feb-16-2022, 01:37 PM
Last Post: buran
  Real time data satyanarayana 3 29,444 Feb-16-2022, 07:46 AM
Last Post: satyanarayana
  Real time Detection and Display Gilush 0 1,833 Feb-05-2022, 08:28 PM
Last Post: Gilush
  time setup for realtime plotting of serial datas at high sampling rate alice93 6 3,888 Jan-07-2022, 05:41 PM
Last Post: deanhystad
  Real-Time output of server script on a client script. throwaway34 2 2,129 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 4,092 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  Plotting A Time Series With Shaded Recession Bars adamszymanski 1 3,230 Jan-24-2021, 09:08 PM
Last Post: nealc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020