joshjaysalazar / IntelliCaster

An AI race commentator for iRacing
GNU General Public License v3.0
3 stars 1 forks source link

Occasional error occurs on commentary stop #78

Closed joshjaysalazar closed 9 months ago

joshjaysalazar commented 10 months ago

Describe the bug Due to what I believe to be a sync issue between threads, an error is occasionally thrown after stopping commentary because commentary is continuing to attempt to generate after the connection to iRacing has already been severed.

To Reproduce Steps to reproduce the behavior:

  1. Start commentary on a replay
  2. Stop commentary right as it is in the middle of generating new text

Expected behavior It should just throw away that commentary line and not throw an exception.

Screenshots/Video N/A

Additional context Here is the traceback:

Exception in thread Thread-7 (run):
Traceback (most recent call last):
  File "C:\Users\joshj\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "C:\Users\joshj\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\joshj\OneDrive\Documents\Git\IntelliCaster/src\core\director.py", line 291, in run
    self._generate_color_commentary()
  File "C:\Users\joshj\OneDrive\Documents\Git\IntelliCaster/src\core\director.py", line 94, in _generate_color_commentary
    self.commentary.generate(
  File "C:\Users\joshj\OneDrive\Documents\Git\IntelliCaster/src\core\commentary.py", line 71, in generate
    text = self.text_generator.generate(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\joshj\OneDrive\Documents\Git\IntelliCaster/src\core\commentary.py", line 233, in generate
    new_msg += f"The race is at {track} in {city}, {country}. "
                                 ^^^^^
UnboundLocalError: cannot access local variable 'track' where it is not associated with a value
joshjaysalazar commented 9 months ago

Duplicate of #79