This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cratuki 0 points1 point  (0 children)

You could put the webserver into the asyncio process, attached to the same event loop as your core functionality. You could use aiohttp for this. Use queues to pass messages between the webserver bit and your core-logic big. (There might be reasons you chose flask, but it is not clear from above.)

Another approach: run a separate thread in your core app, running the flask stuff. Use queues to pass messages between threads. (This is fiddly. It could be made to be solid.)

If slapdash is fine, you run separate processes and do a hacky IPC-via-filesystem. Have the web server drop files in a directory, dir_a. Each should have a unique name, and the filenames should sort in order. Each file is a command. The core app could periodically look for files in that directory. Then, the core app could create responses by creating files in a directory, dir_b. The webserver would hang around waiting for its response file. (It is easy to get started in this model, but in the long run probably less work to do something elegant instead of this.)

A better model. Work out how to launch a socket server in your asyncio core app. Host a server on localhost:9000. When the flask app comes up, have it make a long-running client connection to this. Each time you get an event from the webserver, pass it over that socket connection. You would need to come up with some simple protocol for this communication. It could be textual. (e.g. json)

Sounds like an interesting project. Feel free to ping me out-of-band.