Open ProsperousHeart opened 2 years ago
After removing sleep(0.5) it worked perfectly on my machine.
never ends the program!
That's normal, heartrate always keeps the process alive even after the main program finishes. It printed the factorial of 20, so it was still successful.
The error is in the flask logs as it tries to show a stacktrace highlighting the current node in each frame. It's failing because of the {factorial(num)}
in the f-string. f-strings have some issues which prevent asttokens from retrieving the source code. The fix here is just to prevent it from trying.
After removing sleep(0.5) it worked perfectly on my machine.
Probably becaues the program finished before the webpage had a chance to poll for the stacktrace while it was in the middle of evaluating the f-string.
Oh, really? Shoot, I was creating content based on this post. I didn't know that it keeps it going. How do we stop it?
Do you have a suggestion to allow for this code to work @alexmojaki?
You can set daemon=True
in the trace
call to prevent the flask thread from keeping the process alive. Or just Ctrl+C to kill it.
You can prevent the error in the logs by not doing any logic inside f-strings, e.g.
result = factorial(num)
print(f"The factorial of {num} is {result}")
On a fresh install of python 3.10 and heartrate, the following code:
.... never ends the program!
Here is the error message that happens:
What am I missing here?