[Twisted-Python] Multiple reactors, connecting to self, or other solution?

Oon-Ee Ng ngoonee.talk at gmail.com
Sun Nov 15 19:05:38 MST 2015


On Mon, Nov 16, 2015 at 1:54 AM, Itamar Turner-Trauring
<itamar at itamarst.org> wrote:
> On 11/15/2015 10:19 AM, Oon-Ee Ng wrote:
>>
>> I'm also unable to find any information about connecting to self (for
>> example, to send messages from one reactor to itself).
>>
>>
>
> You can just have a single reactor. E.g. if you do a listenTCP (e.g. on port
> 8080) on the reactor you can in the same process do a connectTCP to
> localhost in the same process on the same reactor; just connect to
> '127.0.0.1' or 'localhost' on port 8080.

Thanks, I was quite sceptical about this but based on your advise I
tried it out and merging ampclient and ampserver does seem to have the
desired effect. Expanding on that, I guess I'll have two factories and
two protocols, one for each 'end', with listenTCP right at the start
and connectTCP run later on when my GUI is ready. Theoretically,
limiting communication to twisted only would mean the client would be
able to access a localhost server and a server on another machine in
exactly the same way.

Do I have to concern myself with race conditions though? Not very sure
how to write tests for those (or if it's even a problem given this is
single-process and single-thread). Basically, will there ever be a
case where my client sends a Command (I'm using amp.Command) and the
server doesn't get it because my overall process is blocked? I assume
there's some sort of timeout which controls that?




More information about the Twisted-Python mailing list