Skip to content

Yaspin pipesafety issues #31

@sebageek

Description

@sebageek

Pipesafety of yaspin does not work for me (or I misunderstood the feature).

When I run yaspin and pipe the output into another program or into a file I'd expect to only see the output of write() calls and maybe of ok()/fail() or other functions with persistant text. Nevertheless I can also see the spinnerstate in programms like less or xxd.

import time
import yaspin

with yaspin.yaspin() as sp:
    sp.text = 'Test'
    time.sleep(0.25)
    sp.write('Hello world')

and when running this script

$ python pipesafe.py |xxd
00000000: 0de2 a08b 1b5b 306d 201b 5b4b 080d e2a0  .....[0m .[K....
00000010: 991b 5b30 6d20 5465 7374 1b5b 4b08 0de2  ..[0m Test.[K...
00000020: a0b9 1b5b 306d 2054 6573 741b 5b4b 080d  ...[0m Test.[K..
00000030: e2a0 b81b 5b30 6d20 5465 7374 1b5b 4b0d  ....[0m Test.[K.
00000040: 1b5b 4b48 656c 6c6f 2077 6f72 6c64 0a08  .[KHello world..
00000050: 0d1b 5b4b                                ..[K

This feels especially weird when using grep. In the case grep matches the spinner text, only the text from write() is displayed:

$ python pipesafe.py | grep Test
Hello world

$ python pipesafe.py | grep Test | xxd
00000000: 0de2 a08b 1b5b 306d 201b 5b4b 080d e2a0  .....[0m .[K....
00000010: 991b 5b30 6d20 5465 7374 1b5b 4b08 0de2  ..[0m Test.[K...
00000020: a0b9 1b5b 306d 2054 6573 741b 5b4b 080d  ...[0m Test.[K..
00000030: e2a0 b81b 5b30 6d20 5465 7374 1b5b 4b0d  ....[0m Test.[K.
00000040: 1b5b 4b48 656c 6c6f 2077 6f72 6c64 0a    .[KHello world.

In an attempt to fix this in an application I'm writing I created a yaspin-like interface, that maps write() to print() and ignores .text plus all other calls to the class. I then replace yaspin with that class if stdout is not a tty, but I'm not sure if this is the way to go for upstream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions