PowerShell: PowerShell should not run follow-up commands before `Format-Table` has finished output
Summary of the new feature / enhancement
Format-Table
, which is implicitly called by a number of Cmdlets, tries to calculate the width of display columns in a separate thread for approx. 300 ms before displaying content.
Start-Sleep
pauses the main thread and, thus, a previous command’s output, still in the pipeline for being displayed, won’t be displayed before Start-Sleep
elapses.
(See here for a description of the problem.)
This is undesired, unpredictable, confusing, unwanted, … behavior.
Proposed technical implementation details (optional)
I suggest to implement a semaphore into Format-Table
/Start-Sleep
that will keep Start-Sleep
from pausing the current thread until Format-Table
has finished displaying its output (in case such output is still pending).
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 40 (4 by maintainers)
Not that I can think of personally. None of these systems talk to each other currently so it would be non-trivial to hook that up. Not impossible of course, but there’s a solid chance that such a fix would only surface different issues. I’d hesitate to recommend anyone try as a PR for this would be very time consuming to even review.
I know, it’s hard to think of this behaviour from a different perspective for those (few) who got acquainted with it over the years. And I comprehend it takes time to overcome this perception bubble that evolved over time.
Still, I suggest (particularly to @daxian-dbw) to free your mind and look at this issue from a fresh, unbiased perspective.
The behaviour is a compromise. In early versions of PowerShell if autosize wasn’t specified the sizing was just screen-width/number of columns, so (IIRC) it did output the first row immediately. That sizing wasn’t good so another solution was tried.
Things getting stuck in the buffer is annoying - especially when debugging, and potential to lose the data in the buffer isn’t good. Do those things outweigh the better use of space? I don’t know enough about other people’s experience; I’ll live with it to get better formatting most of the time
As I said before, Sleep is the easiest way to show what format table does, but there is nothing special about the delay being a sleep command . Put something else slow after the command. for example.
It won’t output anything until there are TWO items AND 300ms has elapsed. Give it one item and it just waits. If we make it more complicated we can see when the second item is received, if 300ms has elapsed, the information is output.
So here there is
If you still think that Format-Table’s timer is paused by the sleep command try this.
If it were the sleep timer delaying format-table, when a timer expires and another command runs execution would find its way back to ft - but it doesn’t. Format-table doesn’t get to do anything until either another item goes in OR the command ends, and if a terminating error occurs before that happens the output is lost.
1 item queued or 300ms not elapsed
but