irclib problems

David Boddie david at boddie.org.uk
Mon Feb 12 17:07:43 EST 2007


On Sunday 11 February 2007 09:29, Tina I wrote:

> I'm playing around with the 'irclib' library working with the first
> example at
> http://www.devshed.com/c/a/Python/IRC-on-a-Higher-Level-Concluded/
> 
> When copying the example verbatim and running it from a console it works
> flawlessly. It connects to the server, join the channel and sits there
> 'forever'...

OK. So it works on its own.

> However, I want to use it in a PyQt application and have done the
> following. I have created a module named 'irclibtest.py' that looks like
> this:

[...]

class Conn:
     def __init__(self):
         # Network information
         self.network = '192.x.x.x'
         self.port = 6667
         self.channel = '#test'
         self.nick = 'IRClibt'
         self.name = 'Python Test'

         # Subclass SimpleIRCClient
         class ClientClass ( irclib.SimpleIRCClient ):
             pass

         # Create an instance of ClientClass and connect.
         self.client = ClientClass()
         self.client.connect ( self.network, self.port, self.nick,
                               ircname = self.name )
         self.client.connection.join ( self.channel )

[...]

> if __name__ == "__main__":
>      app = QtGui.QApplication(sys.argv)
>      f = TircMain()
>      f.show()
>      sys.exit(app.exec_())
> ### Main application end ##
> 
> The problem is that this pings out (PING timeout). As far as I
> understand it rclib.SimpleIRCClient is supposed to handle PING-PONG with
> the server so I don't understand why it does not in my Qt test, but it
> does 'raw'.

You don't call self.client.start() anywhere. Even if you did, you
would still have problems because you need to call app.exec_(), and
this would only happen after self.client.start() returns - if ever.

> I can send to the channel right up to the point it times out by the way.

I think this is just a result of the way the IRC protocol works.

> Anyone know what I'm missing here?

You have an application with two event loops, and you can't run them
both in the usual way. If SimpleIRCClient has a method that only
processes pending events and returns immediately afterwards, you could
create a QTimer, connect its timeout() signal to that method, and make
it fire every half a second or so, to ensure that the client doesn't
time out.

There may be other solutions with threads, but things could get
quite complicated. Making one event loop play well with the other
is probably the best approach to take.

David



More information about the Python-list mailing list