top of page

Await Statements / Event Loops - Shabari Waiting for Lord Rama

How a myth of patience mirrors the magic of Python’s async programming.
By drawing parallels between ancient stories and modern code, programming concepts become much more relatable, fun and easy to remember!

The Devotion of Shabari

In the Ramayana, Shabari is a humble devotee whose faith and patience have become legend. Every day, she sweeps the path, plucks fruits, and waits for Lord Rama’s arrival in her ashram. Years pass, yet Shabari never falters—her task is not complete, her hope not fulfilled, until Rama comes. As soon as he arrives, her years of steadfast waiting are rewarded. Until then, all she can do is wait… and wait.


Shabari’s devotion is the ultimate “event wait”—her entire purpose on pause until the event (“Has Rama arrived?”) finally comes to True.


Event Waiting in Python: Await, Async, and Polling

Modern Python programmers, especially those building web servers, bots, or GUIs, also need patience! Many tasks—downloading data, waiting for user clicks, polling a sensor—require code to “wait” for something to happen before acting. Enter async programming, where we use await statements and event loops to pause code until a certain condition is met.


Story to Code

Shabri's wait in Python:


import asyncio
async def wait_for_rama():
	rama_arrived = False
	while not rama_arrived:
		print("Shabari waits, sweeping the path...")
		await asyncio.sleep(1)  # waits for 1 second, non-blocking

		# Imagine some condition checking here, for demo purpose:
		rama_arrived = check_if_rama_arrived()  # check a real event here

	print("Rama has finally arrived! Shabari's patience is rewarded.")

def check_if_rama_arrived():
	# Dummy function: for demo, let's pretend Rama arrives after 5 checks

	import random
	return random.random() > 0.8

# Run the event loop
asyncio.run(wait_for_rama())

Note: In real-world applications, the function check_if_rama_arrived() would check some external event or data.


What it Teaches About Waiting

  • No Waste: Shabari’s waiting is not “doing nothing.” She prepares, she hopes, she’s ready. Async await in Python allows other things to happen in the background—your program isn’t frozen.

  • Patience Pays Off: The event loop will check—over and over—until the awaited condition becomes True. Only then does the code resume, just as Shabari’s perseverance is finally fulfilled.

Real-World Uses

  • Web servers: Waiting for client requests.

  • Bots: Waiting for new messages.

  • IoT/sensors: Waiting for data input.

  • GUIs: Waiting for a button click.


Just like Shabari does not know when Rama will arrive, your code patiently waits, always ready to celebrate the awaited event!


Wisdom from the Parable

Shabari’s legendary wait reminds us of the beauty in being ready—the art of patient, hopeful anticipation. In Python, mastering await and event loops lets our programs become just as responsive, prepared for moments that matter.


Write your code with Shabari’s spirit: set the condition, wait gracefully, and rejoice when your event finally arrives.
Shabri Maa meeting Lord Rama during Excile
Shabri Maa meeting Lord Rama during Excile

Comments


bottom of page