pg_view icon indicating copy to clipboard operation
pg_view copied to clipboard

Invalid mode 'rU' when realding SystemStatCollector.PROC_STAT_FILENAME

Open vinnix opened this issue 7 months ago • 1 comments

Folks, while trying to make pg_view work on my test environment I came accross the following error:

$ python pg_view.py -U postgres -h localhost -d postgres -p 5464
Traceback (most recent call last):
  File "/home/vinnix/Sources/Github/pg_view/pg_view/__init__.py", line 266, in main
    loop(collectors, consumer, groups, output_method)
  File "/home/vinnix/Sources/Github/pg_view/pg_view/__init__.py", line 87, in loop
    curses.wrapper(do_loop, groups, output_method, collectors, consumer)
  File "/home/vinnix/.pyenv/versions/3.12.9/lib/python3.12/curses/__init__.py", line 94, in wrapper
    return func(stdscr, *args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vinnix/Sources/Github/pg_view/pg_view/__init__.py", line 139, in do_loop
    process_single_collector(st)
  File "/home/vinnix/Sources/Github/pg_view/pg_view/utils.py", line 81, in process_single_collector
    st.refresh()
  File "/home/vinnix/Sources/Github/pg_view/pg_view/collectors/system_collector.py", line 155, in refresh
    stat_data = self._read_proc_stat()
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vinnix/Sources/Github/pg_view/pg_view/collectors/system_collector.py", line 176, in _read_proc_stat
    fp = open(SystemStatCollector.PROC_STAT_FILENAME, 'rU')
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid mode: 'rU'

vinnix avatar May 24 '25 11:05 vinnix

Found in this link: https://stackoverflow.com/questions/38093326/whats-the-difference-between-rb-and-ru-in-the-open-function-for-csv that " As the documentation states, U (Universal Newlines) mode is deprecated; you should not use it anymore. Instead use the newline= keyword argument."

Changing 'rU' to 'r' seems to work. More tests are necessary to be sure.

vinnix avatar May 24 '25 11:05 vinnix