I have this situation:
module1.py:
class AudioEngine:
def __init__(self):
self.liverecording = False
def getaudiocallback(self):
def audiocallback(in_data, frame_count, time_info, status): # these 4 parameters are requested by pyaudio
data = None # normally here we process the audio data
if self.liverecording:
print("Recording...")
return data
return audiocallback
main.py:
import module1
a = module1.AudioEngine()
f = a.getaudiocallback()
f(0, 0, 0, 0)
a.liverecording = True
f(0, 0, 0, 0) # prints "Recording...", which is the expected behaviour, but why does it work?
Question: How to make the callback function audiocallback(...) change accordingly to the new value of a.liverecording? If it works out of the box, why does it?
More specifically, does f, once created with f = a.getaudiocallback(), keep in his code a pointer to a.liverecording (so if the latter is modified, this will be taken into consideration), or a copy of the value of a.liverecording (i.e. False) at the time of the creation of f?