def METHOD_NAME(self, l, n):
    def callback():
        #this function can be interrupted by thread switching so let's
        #use an atomic operation
        l.append(None)
    for i in range(n):
        time.sleep(random.random()*0.02) #0.01 secs on average
        #try submitting callback until successful.
        #rely on regular interrupt to flush queue if we are
        #unsuccessful.
        while True:
            if _testcapi._pending_threadfunc(callback):
                break;