Hello,
i want to control the cancellation of a server process with a value in the Redis-Cache.
To explain the problem, I created a piece of code that iterates through a loop 20 times.
@frappe.whitelist()
def cache_cancel_loop():
if cancel == 0:
for i in range(0, 20):
time.sleep(1)
#Get Cancel-Condition
cancel = frappe.cache().get_value("cancel-condition"))
if cancel is None:
cancel = 0
if cancel >= 1:
break
return {
"cancel": cancel,
"status": 1
}
To stop the loop, I call this Python function via the Javascript function frappe.call() to set the termination variable.
@frappe.whitelist()
def cache_set_cancel():
frappe.cache().set_value("cancel-condition", 1)
return {
"cancel": 1,
"status": 1
}
Why doesn’t the call
cancel = frappe.cache().get_value("cancel-condition"))
return the value 1 within the loop and terminate the loop?
If I make a separate javascript frappe.call() to get the value from the user interface, then the value 1 is returned to me.
@frappe.whitelist()
def cache_get_cancel():
cancel = frappe.cache().get_value("cancel-condition")
return {
"cancel": cancel,
"status": 1
}
I’m confused. ![]()
Thanks in advance for your help.