0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

#python #djago の pdb で pdb.set_trace() 的なデバッグをしたいけど 標準入出力の関係でうまく使えない場合 ( bdb.BdbQuit )

Last updated at Posted at 2019-05-08

ファイルから標準入力を与えてスクリプト実行する場合など

うまくゆかない。

$ python < eg.py

--Return--
> <stdin>(8)<module>()->None
(Pdb)
Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "/Users/yumainaura/.pyenv/versions/3.7.3/lib/python3.7/bdb.py", line 92, in trace_dispatch
    return self.dispatch_return(frame, arg)
  File "/Users/yumainaura/.pyenv/versions/3.7.3/lib/python3.7/bdb.py", line 154, in dispatch_return
    if self.quitting: raise BdbQuit
bdb.BdbQuit

python なら

コマンドオプションでファイル指定しよう。

$ python -m pdb eg.py

django shell なら

標準入力を吸収してから tty とつなげてやれば良さそう。

import pdb

lines = sys.stdin.readlines()
sys.stdin = open('/dev/tty')

pdb.set_trace()

ref

python - Use pdb.set_trace() in a script that reads stdin via a pipe - Stack Overflow

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?