3

"Why does it take a long time for data I send with transport.write to arrive at the other side of the connection?"

Twisted can only send data after you give up control of execution to the reactor. For example, if you have an infinite loop writing data to a transport, the data will never actually be sent since control will never leave your code and return to the reactor."

I found this in the twisted FAQ, it is exactly as my problem. Is there a way to fix this so I can send messages instantly and not wait for the loop to finish?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Bubo
  • 47
  • 5

1 Answers1

4

No. You cannot send messages instantly. Control must return to the event loop. Fortunately, the problem you're really trying to solve (inferred from comments on the question), rate limiting the messages you send, doesn't require being able to do this. Instead, stop using time.sleep in a loop and start using reactor.callLater to delay the execution of code. Or use features of the IRC API which do these things for you (which you seem to have discovered already, lineRate).

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122