Skip to content

Failed to view unicode python string #766

Open
@tespent

Description

@tespent

py-spy failed to preview strings containing multi-byte unicode rune.

thread 'main' panicked at src/python_data_access.rs:413:40:
byte index 123 is not a char boundary; it is inside '试' (bytes 122..125) of `测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测试1测`[...]
stack backtrace:
   0:     0x7f5c50540075 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h358afad87e02ca76
   1:     0x7f5c5057a77b - core::fmt::write::hb19b5b269a2fe458
   2:     0x7f5c5053d45f - std::io::Write::write_fmt::he5a92676a45ef09d
   3:     0x7f5c505411c1 - std::panicking::default_hook::{{closure}}::h3bff550b24d93725
   4:     0x7f5c50540e9c - std::panicking::default_hook::hd53b1b06d2b99687
   5:     0x7f5c50541821 - std::panicking::rust_panic_with_hook::h9fdd87cddb2763da
   6:     0x7f5c50541687 - std::panicking::begin_panic_handler::{{closure}}::h089783ab6b5cba45
   7:     0x7f5c50540539 - std::sys::backtrace::__rust_end_short_backtrace::hed34776d77ef7922
   8:     0x7f5c50541314 - rust_begin_unwind
   9:     0x7f5c5018a453 - core::panicking::panic_fmt::h300583f35f37447a
  10:     0x7f5c5057de8a - core::str::slice_error_fail_rt::hc772242c91d296b2
  11:     0x7f5c5018ab5a - core::str::slice_error_fail::h5aa2312cff950e4e
  12:     0x7f5c5019d370 - py_spy::python_data_access::format_variable::hc0b51a96212725e8
  13:     0x7f5c50221ad5 - py_spy::python_spy::PythonSpy::get_stack_traces::he097640af52b1cd3
  14:     0x7f5c501edc7d - py_spy::dump::print_traces::hbbd519be498666cd
  15:     0x7f5c5029f55f - py_spy::run_spy_command::h03dd3ae83f79b8f1
  16:     0x7f5c502a29ae - py_spy::main::h1d83dfa3c485e787
  17:     0x7f5c501e36e3 - std::sys::backtrace::__rust_begin_short_backtrace::haedd4627941893a7
  18:     0x7f5c5027e909 - std::rt::lang_start::{{closure}}::h92ff100211e3319f
  19:     0x7f5c50535d07 - std::rt::lang_start_internal::h93b3b742566fb30c
  20:     0x7f5c502a38e5 - main

Related code: https://github.com/benfred/py-spy/blob/1fa3a6ded252d7c1c0ff974a4fcd1af67a1577cf/src/python_data_access.rs#L413C5-L413C70

Steps to reproduce the error:

Source code to inspect:

# test.py
import time
def k():
  val='测试1'*500
  time.sleep(120)
k()

run:

#!/bin/bash
python test.py &
sleep 1
py-spy dump -p $(jobs -p) -l
kill $(jobs -p)

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