Code: Alles auswählen
import asyncio
import Thread_1
async def main():
task_1 = asyncio.create_task(Thread_1.start())
task_2 = asyncio.create_task(main2())
await task_1
await task_2
async def main2():
while True:
await asyncio.sleep(1)
Thread_1.Event_msg.set()
asyncio.run(main())
Code: Alles auswählen
import matplotlib.pyplot as plt
import psutil
import asyncio
count = 0
a, b = [], []
Event_msg = asyncio.Event()
async def start():
while (True):
await Event_msg.wait()
Event_msg.clear()
global count
a.append(count)
b.append(psutil.cpu_percent())
plt.xlim(0, 20)
plt.ylim(0, 100)
plt.step(a, b, color='b')
count += 1
plt.pause(0.0000001)
Das ist meine bisher beste Lösung. Richtig zufrieden bin ich aber nicht, weil ich eigentlich gerne direkt den Thread von matplotlib beeinflussen und somit auf die Zeit in plt.pause() verzichten würde. Kann man den Thread direkt steuern, um die Pause-Zeit unendlich zu bekommen?