After my yesterday post using Flask, I was sure that a FastAPI version will be needed, so here it goes:
I have a common scenario which involves:
A sensor collecting information
A web-server publishing the sensor information
Read my previous posts to understand why I think this is the simple way to solve this: Multi-threading.
Thread 1, where an infinite loop request information from the sensor, and stores the latest value to be shared.
Thread 2, where a web-server process requests and share the latest sensor information.
Easy ! And after a couple of tests, I manage to create a single file implementing this:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
One response to “#Python – #FastAPI Webserver sharing information from values in a different thread”
Udaya Unnikrishnan
Hi El Bruno, I came across your awesome blog while I am searching how to share information to background thread from Flask Webapp entry function. I would like to refer your work ( reference image in this blog , Thermal Detector Labs ) . I have searched entire posts, but I could not find it. Kindly share your approach for sharing the frames captured from the webcam to background work and to display it result in new window. Thank you.
Leave a comment