Two independent async loops in Python
<p>What would be a good approach to execute two asynchronous loops running in parallel in Python, using <code>async/await</code>?</p>

<p>I've thought about something like the code below, but can't wrap my head around how to use <code>async</code>/<code>await</code>/<code>EventLoop</code> in this particular case.</p>

<pre><code>import asyncio

my_list = []

def notify():
    length = len(my_list)
    print("List has changed!", length)

async def append_task():
    while True:
        time.sleep(1)
        await my_list.append(random.random())
        notify()

async def pop_task():
    while True:
        time.sleep(1.8)
        await my_list.pop()
        notify()

loop = asyncio.get_event_loop()
loop.create_task(append_task())
loop.create_task(pop_task())
loop.run_forever()
</code></pre>

<p>Expected output:</p>

<pre><code>$ python prog.py
List has changed! 1 # after 1sec
List has changed! 0 # after 1.8sec
List has changed! 1 # after 2sec
List has changed! 2 # after 3sec
List has changed! 1 # after 3.6sec
List has changed! 2 # after 4sec
List has changed! 3 # after 5sec
List has changed! 2 # after 5.4sec
</code></pre>