[Tutor] Fwd: Re: Rerouting a traceback

Jim Byrnes jf_byrnes at comcast.net
Thu Jan 28 13:34:19 EST 2021



I goofed, I sent this reply straight to Mats not to the list.

-------- Forwarded Message --------
Subject: Re: Rerouting a traceback
Date: Tue, 26 Jan 2021 15:02:16 -0600
From: Jim Byrnes <jf_byrnes at comcast.net>
To: Mats Wichmann <mats at wichmann.us>

On 1/25/21 9:15 PM, Mats Wichmann wrote:
> 
> On 1/25/21 7:21 PM, Jim Byrnes wrote:
>> Linux Mint 20 - Python 3.8
>>
>> Is it possible to reroute a traceback to a GUI wintow?
> 
> It's software, so it's possible...

snip>

> If the script you launch is your own - that is, if you feel like 
> modifying it - it can just pop up a simple message box. This might end 
> up being sufficient:

I wrote the scripts.

> from tkinter import messagebox
> 
> messagebox.showerror("FAILED", "error message from the failure")
> 

The scripts are not really gui's. I just use pyautogui to provide a 
convenient way to enter a date. I mentioned pysimplegui (a wrapper 
around tkinter) because I might be able to use it's debug window to 
print the traceback, so far I haven't been able to figure it out.

> but you'll need to ampliy what you need and who controls what in this 
> scenario, it might be more complicated.

The code below is the heart of a lengthy function. Before the loop I 
gather the info it needs to process.


     # Get historical stock prices from yahoo using yfinance
     for stock in stocks:
         while True:
             try:
                 ticker = yf.Ticker(stock)
                 hist = ticker.history(start=day)
                 close_price = hist.loc[day]['Close']
                 closing_prices.append(close_price)
             except:
                 print ('yfinance JSONDecodeError DAILY, retyring')
                 continue
             break

After the loop I process the info in the spreadsheet.

Sometimes it takes a little while for the loop to complete. Mean while I 
watch the spreadsheet waiting for it to up date. After a while I decide 
something went wrong and then rerun the script from the terminal to see 
the trackback.

What I want to do is see the traceback when the problem occurs instead 
of waiting and then rerunning the script in the terminal. The errors are 
not with the scripts code. I may have entered a date when the markets 
were closed or yahoo just timed out. The traceback lets me figure that out.

Thanks,  Jim


More information about the Tutor mailing list