[Twisted-Python] Request for ideas

Samuel Reynolds sam at SpinwardStars.com
Sat Dec 3 19:06:52 EST 2005

At 2005-12-03 04:24 PM -0500, you wrote:
>The specific problem occurs when objects are reused. I've had situations 
>where a client fails to reply for significantly longer than the timeout 
>period. In that interval, the original CommTrans, AckMgr and RepMgr have 
>been deleted and replaced by new instances. The client finally replies to 
>the original request, and the reply is caught by those new objects!
>(There is what I think is a very small, but non-zero probability that I'm 
>misinterpreting what I'm seeing.)
> From what I can see in the source code, the internal ID is what's set by 
> the builtin 'id' function. I'm printing these at key times and I can see 
> where they're being duplicated. The only time I see this problem occur is 
> when a new object has been created with the same id as a previous object.

Sounds like an object aliasing problem.
And I don't think that it's *objects* that are being
re-used, but *memory locations* for same-class objects.

Don't use the built-in id() function. I'm not sure if this
is correct, but it seems to me something like the memory
address of the object. When the memory gets re-used, the
same ID sometimes recurrs.

If you need a unique identifier for your application logic,
create and assign it yourself. Don't use the id() function.

One possibility is to give each AckMgr/RepMgr pair an auction ID.

Create a simple ID generator (object or function).
When you create a new AckMgr and RepMgr, get a new ID
from the generator and assign it to each one *before*
you use it.

The AckMgr then could simply ignore any response that
doesn't have the expected ID.

More generally, I would put the AckMgrs in a dictionary,
keyed by the action ID. I would have *one* function/method
(ProcessAck) that gets responses and dispatches them to the
appropriate AckMgr, or drops them if no matching AckMgr
is found. This would make testing, debugging, and tuning
easier, too, by providing a single location for

- Sam

Spinward Stars, LLC                        Samuel Reynolds
Software Consulting and Development           303-805-1446
http://SpinwardStars.com/           sam at SpinwardStars.com  

More information about the Twisted-Python mailing list