Closed bjorn-spire closed 7 years ago
Oh, to validate that the threads aren't killed between invocations I created a new lambda and ran it a couple of times and saw that the count went up:
from threading import Timer, active_count
def handler(event, context):
def end_of_timer():
print('end of timer!')
t = Timer(290, end_of_timer)
t.start()
print('Currently active threads: {}'.format(active_count()))
Thats a good point. We hadn't noticed this previously.
Because lambda doesn't actually stop the Python processes proper after each execution the threads would linger around after finishing. After enough invocations of your function it would start failing from:
By collecting all the timers and then canceling them at the end of function execution we're no longer seeing this resource constraint.
Also fixed a completely unrelated bug with time_remaining. While writing the test I got an invocation of it and saw that it couldn't run because the
config
object was splatted out to 8 arguments instead of the one config as expected. :)