crowdwave / maryjane

MIT License
153 stars 8 forks source link

Mixing sync and async apis? #1

Closed esamattis closed 3 years ago

esamattis commented 3 years ago

Cool project! Thanks for sharing.

I haven't done much async Python but it looks like you are using syncronous apis within async code which blocks the event loop. AFAIK the core file apis in Python are sync. At least on node.js in this would be a bad practice.

https://github.com/bootrino/maryjane/blob/a1d7a3376a7a03e195e31221f473beeea33b895f/mjpegserverpython.py#L27-L28

I think you should use some async version of open()/read() 🤔

ghost commented 3 years ago

I started off with the (blocking) code that you see. I then tried to add async file loading using aiofiles, and it stopped working. So I switched back to the blocking file load and it worked again. I figured that since the frame is being loaded from a RAM drive it would be extremely fast, even if blocking. So yes you are correct, ideally it would use non blocking file load but I made the pragmatic decision to leave it as blocking. If you can make it work with non blocking file load then I'll make the change.

EDIT: further research appears to show that there's no async file handling in Python because Linux does not have async file handling. So it seems the blocking file load is the right thing to do.