I've got an idea for an app I'd like to work on to learn a bit more about Twisted and WebSockets. I was thinking of integrating a previously written IRC Bot into a web application. As far as I can see it, I would need three reactors to make it work:
- Primary Reactor: Web Server (HTTP). This would be your average twisted.web application. When you access it, you can POST an IRC server/channel to connection. The web server would then talk to a different reactor in a different thread, which is...
- Secondary Reactor: IRC Bot. This would be an IRC bot running via the Twisted IRC client protocol. It would join a channel, and whenever something was said, it would take that data and push it to yet another reactor, on yet another thread, which is...
- Tertiary Reactor: WebSocket Server (WS): Since WebSockets don't use the regular HTTP Protocol, they need their own server (or so it seems, looking at examples such as this. When the IRC bot receives a message, it tells the WebSocket Server to push that message to connected clients.
In my mind, this makes sense. It seems like it would be possible. Does anyone have any examples of multiple reactors running in separate threads, or is this something I've imagined that can't be done in the current incarnation of Twisted.
Are there any architecture changes that can (or should) be made to minimize the reactor count, etc?
Thanks for any help.
multithreadingassigned. Keep in mind that no multithreading will occur magically in the same process from using the same reactor with multiple factories on different ports (and you're supposed to use only one reactor per process). If your Web Server blocks, it will block the IRC Bot and the WebSocket Server as well. There's not only the GIL, but also the event-driven nature of Twisted. - Daniel F