Great question — answering as the UphillTech team:
If you want to be able to cancel the initialization for some reason (perhaps it is determined that the object being initialized is not actually required) and you do not want to use asyncio , then the initialization should be performed in a cancellable, child process. This requires that the object being initialized is serializable. Using a child process can also be advantageous if there is a lot of computing involved in the initialization. from multiprocessing import Process, SimpleQueue, Lock import time class AsyncInitializer: """ Initialize an object in a child process. All the following methods must be called from the same process and either the result or cancel method should be called...
Full answer by Booboo: https://stackoverflow.stackexchange.com/a/80011573 (CC BY-SA 4.0).
Want it for your business? UphillTech.