#๐Ÿ”’ Code after function silently fails to run

41 messages ยท Page 1 of 1 (latest)

mortal pine
#

https://pastebin.com/NQvi0Mh9
This is a test script for a STT tool I'm making. The purpose of the tool is to identify a pokemon name from speech, and then display relevant information.
I'm currently working on the STT portion. I'm using the faster-whisper model, and fuzzymatching to identify the pokemon name from speech correctly.
The test script has a function, compare_transaction() which iterates over 251 pokemon name recordings, transcribes each one, and puts information about the transcription into a dictionary. compare_transaction() then returns the dictionary.

I call the compare_transaction() on line 72. All the code from this function runs and the loop completes. The proceeding lines do not get run after calling this function. The proceeding statements are print statements, and writing the dict to json. The print statements are not shown in the terminal, and the json file is not written.
If I modify compare_transaction() to run a limited number of times, it will run the proceeding code successfully. I have not tested this exhaustively, so as to find the "edge" of where this will fail or succeed, and have only limited the loop to running 10 times to see if it would work.

I would really appreciate any help understanding why this apparently fails without any errors.

lost mothBOT
#

@mortal pine

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mortal pine
#

Snippet of the end of the terminal output from running this script.

{'real_text': 'ho-oh', 'original_transcribed': ' ho-oh', 'fuzzy_transcribed': 'ho-oh', 'fuzzy_match_certainty': 100, 'language': 'en', 'probability': 0.8984635472297668, 'original_equals_real': False, 'fuzzy_equals_real': True, 'transcribed_equals_fuzzy': False}
250
<class 'dict'>
6576
{'real_text': 'celebi', 'original_transcribed': ' celebi', 'fuzzy_transcribed': 'celebi', 'fuzzy_match_certainty': 100, 'language': 'en', 'probability': 0.9938305020332336, 'original_equals_real': False, 'fuzzy_equals_real': True, 'transcribed_equals_fuzzy': False}
251
<class 'dict'>
6576

(venv) D:\Programming\Python\pokemon-helper\src>
strong harness
#

did you try to debug line by line if you're using an IDE that allows for it ?

#

if i understand your output right, those are the prints inside the loop, and then when the function concludes, you get neither the prints that should display after nor an error message, is that right ?

#

(little side not but it seems you have a redundant try except block there)

mortal pine
strong harness
#

so i can see only 2 ways it would do that :
Either you have a system interruption and there's no exception to catch or the print somehow gets intercepted, but you print to stdout and you have other prints that shows so that seems unlikely

#

i don't think it's that but did you try removing this line ?
sys.setrecursionlimit(3000)

mortal pine
#

Likewise, the redundant try-except block is because 1. I don't have a lot of experience with try-except and 2. i just slapped them in to see if i could catch something

strong harness
#

it shouldn't impact the results, it means it automatically stops when you have 3000 layers of recursion, but you should have only 2 at most right now

mortal pine
#

Ok, I wasn't sure. This was something Phind suggested

strong harness
#

unfortunately i have no idea what might happen, i can only advice you to try to debug line by line, you know how to do it ?

mortal pine
#

I know how to pause and step-into

strong harness
#

put some random code after the for loop inside your function (like a print) and put a breakpoint on it

#

(click at the left of the line number to set a breakpoint)

#

and then when you debug, it will stop there

mortal pine
#

ahh okay

#

i'll put one on the data assignment outside the function too

strong harness
#

also instead of printing every single thing inside your loop, id use something like tqdm

#

which allows you to have a progress bar on any loop easily

mortal pine
#

neat, i'll use that thanks!

strong harness
#

install tqdm and then
from tqdm.auto import tqdm
for i, recording in tqdm(enumerate(sorted_recordings_list)):

mortal pine
#

i actually was initially just dumping the entire dict to console

#

at some point it starts getting cut off

strong harness
#

now we wanna see if we get a return from this function

mortal pine
#

which seems weird because i've definitely printed huge dicts to terminal before

strong harness
#

and if no, if the loop stops somewhere

mortal pine
strong harness
#

the one after the for loop should be enough

mortal pine
#

i just did that

#

thanks so much for your help, i won't ask you to hand hold me anymore. i thought maybe this was an issue where the problem is apparent to someone with more experience

#

i'll research debugging tools some more. it's not something i've really used before. it would definitely have saved me time in the past ๐Ÿ˜…

strong harness
#

yes its very handy

#

good luck

lost mothBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.