[Twisted-Python] How to stuff new events into the core event loop?
exarkun at divmod.com
exarkun at divmod.com
Fri Oct 15 12:27:02 EDT 2004
On Fri, 15 Oct 2004 17:47:51 +0200, "Ames Andreas (MPA/DF)" <Andreas.Ames at tenovis.com> wrote:
>Hello all,
>
> I'm pretty new to twisted activity (just some doc and code reading so
> far). So please be forbearing if the answers to the following
> questions are obvious.
>
> I'm wrapping some C library which implements some networked client to
> use it from python, i.e. from a twisted app. Within the guts of this
> lib there is a thread created (i.e. it is normally never seen by
> python). This thread manages some heartbeat mechanism. I, as a user
> of this API, can register a callback with the lib. This callback is
> called _within the context of this underground thread_, when the
> connection to the server is lost (as recognised through the
> heartbeat). Now my first question is, how you would stuff that event
> (loss of server connection) into the core event loop?
To post an event to the reactor:
reactor.callFromThread(f, *a, **kw)
For example, in your connection lost callback, you might wish to do something like this:
def blahblahConnectionLost(connectionId, exitStatus, monkeys):
reactor.callFromThread(
someKindOfThing.connectionLost,
Failure(Exception(exitStatus, monkeys)))
Jp
More information about the Twisted-Python
mailing list