Fix erros with long output and simplified p.poll handling

Related to #5832