quarnster/SublimeGDB — pull request #50 by alexleach (2013-05-14 23:30:30+00:00)
Title: Make sure all program output is printed before closing `gdboutput`.

I was very confused when under debug mode, I wasn't seeing the full program output from a set of Python unit-tests. It turns out this is because the SublimeGDB stdout handlers (`programio` and `gdboutput`) both test to see if `gdb` is still running, each iteration of their loops.

With `posix` buffering between processes, my main program (`python`) exits before all its output has been read by these parent threads, so I had never seen all the output from my unittest runs.

Although my head was scratching for a while, I found that two or three tweaks to the loops in `sublimegdb.py` are all that is needed to get all output to the Sublime console:

* [Line 1356-1382] - in `gdboutput` : Break loop when the length of `readline()` is 0, instead of when `gdb` has finished. This requires deferring the call to `strip().decode(...` until after checking the line's length is nonzero.

* [Line 1437] - in `programio.MyFD.readline` : Don't execute `.poll()` in this loop. Each iteration of this loop reads only a single characters in at a time, so calling `poll()` each time is pretty inefficient, and it can be left up to the calling function...

* [Line 1469,1475] - In `programio` : Defer testing if process is alive until after `readline` has been returned (probably not necessary with the above two changes, but this works well).

___________

Whilst I had `sublimegdb.py` open, I thought I'd also make all comparisons against None, proper null pointer comparisons. This is much quicker than looking up an object's `.__eq__` or `.__neq__` method, which is what happens when `None` is compared using `!=` or `==`.

[Line 1356-1382]: https://github.com/alexleach/SublimeGDB/commit/789b9b917f53dbace102d137c9889cd2a889547a#L0L1356
[Line 1437]: https://github.com/alexleach/SublimeGDB/commit/789b9b917f53dbace102d137c9889cd2a889547a#L0L1437
[Line 1469,1475]: https://github.com/alexleach/SublimeGDB/commit/789b9b917f53dbace102d137c9889cd2a889547a#L0L1469