fabric/fabric — pull request #733 by octplane (2012-09-19 11:57:35+00:00)
Title: Fix for #715

Hi,

I've completed refactoring the read loop completely. Here is a summary of the changes I've made:

- Created class for the SSH Channel Reader
- In the main reading loop, I've clearly separated the printing part and the interactive/capture part because printing require very careful carriage return accounting, while interactivity/capture only requires conservation of the network stream,
- The printing part is a very small state machine that handles prefix and carriages returns correctly across network read,
- The network is now read in chunk of 4096 bytes (arbitrary value). Every chunk is then parsed on a part-of-line by line basis. Part of line is added to current line (if needed) and processed,
- SSH Channel is now read with a 0.1s timeout.

As a result, the performance of the network read loop is much better (on my sample 14000 lines of log run, the performance goes from 1m30s to 34s (only 3s slower than raw SSH).

I think the overall refactoring is of acceptable quality, although some expert Pythonist could probably improve some parts of the code without a doubt.

All tests do pass and there is nothing to configure to adapt to the speed/interactiveness tradeoff. We have the best of two worlds !