I have a p5py application that requires getting data from the internet on user input. I’m running the sketch with no_loop() in the setup as animation is only required on user input.
Fetching and processing the data can take a second, but the user input is available immediately and I would like to draw it to the screen right away, then do the fetching and processing.
The following code is inside of key_pressed(), which keeps track of user input in the object user_input
if key == 'ENTER':
# assign the global variable text_to_display to whatever the user typed
text_to_display = user_input
# call draw to render that text to screen
redraw()
# get and process data from the input
get_and_process(user_input)
I would expect redraw to execute before get_and_process is called, but that’s not happening. I see the redrawn results only after get_and_process is complete.
Maybe something analogous to p5’s request animation frame step is happening. Is there a way for me to force redraw to execute before the program moves on? Or to call get_and_process as a callback on redraw()?