Re: [Twisted-Python] Really Basic clarification on defers

2009-08-06 Thread John Aherne
I'll try and put all my comments together with the feedback from everyone. Then I can pass it over to the defer documentation thread to see if they are interested in any part of it. John On Thu, Aug 6, 2009 at 8:02 AM, John Aherne wrote: > > > On Thu, Aug 6, 2009 at 1:12 AM, Jarrod Roberson wro

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-06 Thread John Aherne
On Thu, Aug 6, 2009 at 1:12 AM, Jarrod Roberson wrote: > > > On Wed, Aug 5, 2009 at 6:04 PM, John Aherne wrote: > >> >> >> 2. If you have blocking code - *please define blocking* :), then first >> think about putting it into deferToThread with appropriate callbacks and >> return the deferred. As

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-06 Thread John Aherne
A point I missed out on: The adbapi module seems to be a good example of using deferreds and threads. The adbapi module returns a deferred it has created, you add your callbacks to it. It calls your callback when ready. It does seem like the examplar for doing deferreds. The db stuff will normally

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-05 Thread Jarrod Roberson
On Wed, Aug 5, 2009 at 6:04 PM, John Aherne wrote: > > > 2. If you have blocking code - *please define blocking* :), then first > think about putting it into deferToThread with appropriate callbacks and > return the deferred. As suggested by Jarrod in his response. > > > blocking code is code th

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-05 Thread John Aherne
On Wed, Aug 5, 2009 at 4:17 PM, wrote: > On 09:33 am, johnahe...@rocs.co.uk wrote: > >On Wed, Aug 5, 2009 at 12:14 AM, Johann Borck > >wrote: > >> > >[snip] > > > >Sendline is not blocking so as you say we can avoid the use of > >deferreds and > >continue to use sendline directly. > > LineReceive

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-05 Thread exarkun
On 09:33 am, johnahe...@rocs.co.uk wrote: >On Wed, Aug 5, 2009 at 12:14 AM, Johann Borck >wrote: >> >[snip] > >Sendline is not blocking so as you say we can avoid the use of >deferreds and >continue to use sendline directly. LineReceiver.sendLine is not blocking, correct. However, your statemen

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-05 Thread John Aherne
On Wed, Aug 5, 2009 at 1:11 AM, Aaron Bush wrote: > A note on how I handled a similar situation in regards to the timeout > requirements you seem to have: > > I had a similar setup where I was forwarding data from clients to servers > and back and forth, etc. I wanted to timeout the connection a

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-05 Thread John Aherne
On Wed, Aug 5, 2009 at 12:14 AM, Johann Borck wrote: > > On Tue, Aug 4, 2009 at 10:08 AM, John Aherne > wrote: > > This is a really basic problem we are trying to decide about, > > > > We have programs that run quite happily, so far. Its main task is to > > receive d

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-05 Thread John Aherne
Thanks for the reminder about deferreds. I think the problem is more to do with knowing what role the reactor and select perform. I assume that sending and receiving data with sendline and linereceived are not blocking. So for our simple case we can ignore deferreds. They provide no benefit. Thi

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-04 Thread Aaron Bush
A note on how I handled a similar situation in regards to the timeout requirements you seem to have: I had a similar setup where I was forwarding data from clients to servers and back and forth, etc. I wanted to timeout the connection after some idle time and ended up using the TimeoutMixin found

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-04 Thread Johann Borck
On Tue, Aug 4, 2009 at 10:08 AM, John Aherne mailto:johnahe...@rocs.co.uk>> wrote: > This is a really basic problem we are trying to decide about, > > We have programs that run quite happily, so far. Its main task is to > receive data from port A and send it out via port B. Then receive data > v

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-04 Thread Jarrod Roberson
Deferreds don't do what you think they do. They don't do anything to make your code non-blocking. They only adhere to a contract that something will eventually be returned. The most common use of deferred's to make your code non-blocking is to use .deferToThread() or some other mechanism to make th

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-04 Thread John Aherne
Kevin Thanks for the reply. It's good to get some feedback on how someone else would go about tackling a particular issue. It helps to confirm whether what you a retrying makes sense. Thanks John Aherne On Tue, Aug 4, 2009 at 7:35 PM, Kevin Horn wrote: > On Tue, Aug 4, 2009 at 10:08 AM, John

Re: [Twisted-Python] Really Basic clarification on defers

2009-08-04 Thread Kevin Horn
On Tue, Aug 4, 2009 at 10:08 AM, John Aherne wrote: > This is a really basic problem we are trying to decide about, > > We have programs that run quite happily, so far. Its main task is to > receive data from port A and send it out via port B. Then receive data via > port B and send it out via po

[Twisted-Python] Really Basic clarification on defers

2009-08-04 Thread John Aherne
This is a really basic problem we are trying to decide about, We have programs that run quite happily, so far. Its main task is to receive data from port A and send it out via port B. Then receive data via port B and send it out via port A. It's pretty much like a chat setup. You just build up a l