Closed MoaMoaK closed 5 years ago
Hi, and thanks for checking out the IRC lib!
Because of the nature of IRC, the client needs to be connected and responding to events (such as pings from the server). Therefore, something needs to regularly (continuously) call process_once, and that's what process_forever does.
There are several ways you can work within this constraint.
Probably the easiest way would be to configure your client to run in a thread... and you may be able to still send messages from that client in your main thread.
Another way would be to create an event loop for your application that periodically calls process_once, and have that event loop handle concurrency across the two domains (IRC client and your app's behavior).
Yet another way would be to hook into the IRC Client's event loop, having it call your application's behavior.
For an example, this plugin for pmxbot starts up a web server. At startup, it creates a web server that posts messages to a queue, and the event loop periodically relays messages from that queue to the IRC connection.
There are probably other opportunities if you use the asyncio client, but I'll admit I haven't used it yet, so wouldn't even be able to provide a good example.
I hope that helps.
I want to write a client which can send messages to a channel when an external function triggers it. Basically doing something like:
So I wrote a very basic
IRCClient
class inspired by scripts/irccat2.py:The problem is the process is getting stuck in the loop of the
self.start()
call and never reaches thea.send(...)
calls. And not callingself.start()
prevents the messages to be transmitted to the server. So is there a way to not completely block the process but still be able to send messages later in the process ?