[Twisted-Python] iConnector factory not what expected

Martin martin at webscio.net
Fri Jun 15 10:46:27 MDT 2012


On 15/06/12 14:15, exarkun at twistedmatrix.com wrote:
> On 08:50 am, martin at webscio.net wrote:
>> On 15/06/12 01:40, exarkun at twistedmatrix.com wrote:
>>> On 14 Jun, 03:34 pm, martin at webscio.net wrote:
>>>> Hi again,
>>>>
>>>> I've a bit of code that does the following:
>>>>
>>>> f = MyReconnectingClientFactory()
>>>> iConn = reactor.connectSSL(url, port, f, ssl.ClientContextFactory())
>>>>
>>>> now I would expect that iConn.factory would be my f, but as it turns
>>>> out
>>>> it's an instance of some TLSMemoryBIOFactory.. Why is that so?
>>>>
>>>> After some digging, I was able to find f under
>>>> iConn.transport.protocol.wrappedProtocol.factory.. I'm happy to use
>>>> that, but it just sounds a bit weird to me.. or is this normal?
>>> There is no "factory" attribute on the `IConnector` interface at all:
>>>
>>> http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IConnector.html
>>>
>>> Neither is there a "transport" attribute, nor do any of the transport
>>> interfaces have a "protocol" attribute.
>>>
>>> All this means that Twisted isn't promising you anything about the
>>> meaning or existence of any of these attributes.
>>>
>>> So, why don't you just use `f` instead?
>>>
>>> Jean-Paul
>>>
>>> _______________________________________________
>>> Twisted-Python mailing list
>>> Twisted-Python at twistedmatrix.com
>>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>> I can't use f because I'm saving the IConnector object for later, so
>> that I can disconnect it when needed. I'm not sure if saving the f
>> object would have any effect, since doing anything to that after the
>> connection was created will surely have no effect, or?
> This doesn't make sense.  `f` is not an object and neither is
> `connector.factory` nor
> `connector.transport.protocol.wrappedProtocol.factory`.  They're
> expressions that, at least in this case, and in the context you're using
> them, all evaluate to the same object: the MyReconnectingClientFactory
> instance created at the beginning of your example code.
>
> It doesn't matter which of them you call stopTrying on, since there
> isn't actually any "them", there's just the single factory object.
>
> Put another way, saving `f` will let you do exactly what you want, in
> part because it's no different from what the `IConnector` implementation
> happens to be doing.
>
> Jean-Paul
>> In general, I can do iConn.disconnect(), but this being a
>> ReconnectingClientFactory, it attempts to reconnect straight away..
>> That's why I was looking to get the factory object somehow, so that I
>> could call stopTrying() on it first. If there's a better approach to
>> this, please let me know :)
>>
>> Thanks
>>
>> _______________________________________________
>> Twisted-Python mailing list
>> Twisted-Python at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
Hm OK. As I said I'm completely new to this. I just figured that since 
the f instance was created before the connection was made, it would not 
be really related to the connection.

What happens if I create two SSL connections with the same factory f? 
Would calling "stopTrying" on that f then affect both connections? Or 
just the last? I guess I can simply test this out myself, it's just 
slightly weird to me. :)




More information about the Twisted-Python mailing list