r/Python • u/autokitteh • May 21 '24
Discussion Durable Python - Infrastructure failures should not stop the process
Durable Python enables developers to write Python code while an underlying system ensures reliability and resilience.
It automatically handles state persistence, fault tolerance, and retry mechanisms, allowing developers to focus on business logic without worrying about infrastructure concerns.
Consider the following code, in case the process terminates in the middle of execution, in case the process is killed or due to hardware failure, the process will not complete.
import requests
import time
SLEEP_SECONDS = 3
URL = "http://localhost:9980/webtools/api/msgs"
def on_http_get(data):
for i in range(10):
print("Loop iteration: %d of 10" % (i + 1))
# Send a POST request to the application
requests.post(URL, data = "This is my " + str(i) + " iteration...")
time.sleep(SLEEP_SECONDS)
But actually, I would like the process to survive restarts and continue from the spot it terminated, especially if it's a long running process. For this we need Durable Python.
I was wondering which use cases can take advantage of this technology.
37
u/FailedPlansOfMars May 21 '24
You dont want durable code. Simple solution below:
1, Store state outside the process, a file will do. 2, update file after each post. 3, run as service in the os with restarts. 4, dont catch errors.
This way you can update the code, restart the service easy, restart/ replace the server. Scale by moving the file to a db and run multiple instances.
No need for code level handling of this at all.