python logging library init.py returns keyerror and acquireLock() is NoneType

195 Views Asked by At

Im absolutely not sure which library is causing this or what is causing this but i really would appreciate some help. Although the error isn't messing up with the answers it pops up at the end of the program which im not sure why that is.

GITHUB : https://github.com/aaryanDhakal22/moccint

The error that pops up after the final line of the code has executed

import pyttsx3
import speech_recognition as sr
import spacy
from study import study
from colored import fg, attr

r = sr.Recognizer()

mic = sr.Microphone()

nlp = spacy.load("en_core_web_lg")

for index, records in study.items():

    question = records[0]
    answer = records[1]

    engine = pyttsx3.init()
    engine.say(question)
    engine.runAndWait()
    engine.stop()
    
    print("Listening now")

    with mic as source:
        r.adjust_for_ambient_noise(source)
        audio = r.listen(source)

    print("Done listening\n")

    audio_traslated = r.recognize_google(audio)
    print("Done Translating")
    nlp_answers = nlp(answer)
    nlp_user_answers = nlp(audio_traslated)

    similarity = nlp_answers.similarity(nlp_user_answers)

    if float(similarity) > 0.9:
        print("%sPASSED%s" % (fg(2), attr(1)), similarity)
    else:
        print("%sFAILED%s" % (fg(1), attr(0)), similarity)

    print("Q : " + question + "\n")
    print("A : " + answer + "\n")
    print("Your : " + audio_traslated + "\n")

Note :

  1. The error pops after the final line has been executed
  2. Running the code from vscode run and debug by pressing step over doesnt show the error
  3. The logic of the program works and the error doesnt seem to be influencing the answers
  4. The error occured towards the end so it probably isnt the setup or virtualenv fault , maybe the loop maybe something else not sure
1

There are 1 best solutions below

2
On

I can't be sure, but it looks as though it's because something is trying to log during program exit, when some Python objects (including built-ins) become unavailable as the interpreter shuts down.