Fix errors with long output and simplified p.poll handling

Related to #5832