Currently, it is in a While loop, should try to re-write with reactor.callLater and deferred to have a chance to check the running state for very 1000 entries
the transaction instance is lost if the subroutine was run by reactor.callLater or threads.deferToThread, so the improvement was done by add a check point for context.running() every fetching chunk (1000 entires).
Currently, it is in a While loop, should try to re-write with reactor.callLater and deferred to have a chance to check the running state for very 1000 entries