Search code examples
pythontensorflowwebsocketpython-asynciopython-multithreading

Python tensorflow: asyncio or threading


I am implementing a server for recognizing objects in photos using tensorflow-gpu in "semi-real" time. It will listen for new photos on a websocket connection, then enqueue it into a list for the detector run when it is free. Would it be simpler to use asyncio or threading to handle the websocket listener and the recognition queue?


Solution

  • Ultimately I used asyncio to handle the websocket connection, enqueuing incoming images to a queue. I used threading which had a thread to read the image into RAM, extracted some metadata, and queued it for the object detector. The detector, running in another thread, tagged the images and queued the tags in the database handler (yet another thread).