Skip to content

py-spy panics if stdout is closed #806

@royjacobson

Description

@royjacobson

Hi!

It's a really silly bug, but I noticed that if I run py-spy and pipe it into head, it will crash while trying to print to a pipe that was closed already:

$ RUST_BACKTRACE=1 py-spy dump --pid 3547707 | head 
[...]
Thread 3547707 (active): "MainThread"
    _mean_shift_single_seed (sklearn/cluster/_mean_shift.py:118)
    __call__ (sklearn/utils/parallel.py:136)
    _get_sequential_output (joblib/parallel.py:1847)
    __call__ (joblib/parallel.py:1918)
    __call__ (sklearn/utils/parallel.py:74)
    fit (sklearn/cluster/_mean_shift.py:502)
thread 'main' panicked at library/std/src/io/stdio.rs:1118:9:
failed printing to stdout: Broken pipe (os error 32)
stack backtrace:
   0:     0x14a5318f5075 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h358afad87e02ca76
   1:     0x14a53192f77b - core::fmt::write::hb19b5b269a2fe458
   2:     0x14a5318f245f - std::io::Write::write_fmt::he5a92676a45ef09d
   3:     0x14a5318f61c1 - std::panicking::default_hook::{{closure}}::h3bff550b24d93725
   4:     0x14a5318f5e9c - std::panicking::default_hook::hd53b1b06d2b99687
   5:     0x14a5318f6821 - std::panicking::rust_panic_with_hook::h9fdd87cddb2763da
   6:     0x14a5318f6687 - std::panicking::begin_panic_handler::{{closure}}::h089783ab6b5cba45
   7:     0x14a5318f5539 - std::sys::backtrace::__rust_end_short_backtrace::hed34776d77ef7922
   8:     0x14a5318f6314 - rust_begin_unwind
   9:     0x14a53153f453 - core::panicking::panic_fmt::h300583f35f37447a
  10:     0x14a5318f149c - std::io::stdio::_print::h52a781f07ee171ab
  11:     0x14a5315a3dea - py_spy::dump::print_trace::h5011550a273dd3fd
  12:     0x14a5315a3268 - py_spy::dump::print_traces::hbbd519be498666cd
  13:     0x14a53165455f - py_spy::run_spy_command::h03dd3ae83f79b8f1
  14:     0x14a5316579ae - py_spy::main::h1d83dfa3c485e787
  15:     0x14a5315986e3 - std::sys::backtrace::__rust_begin_short_backtrace::haedd4627941893a7
  16:     0x14a531633909 - std::rt::lang_start::{{closure}}::h92ff100211e3319f
  17:     0x14a5318ead07 - std::rt::lang_start_internal::h93b3b742566fb30c
  18:     0x14a5316588e5 - main

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