Explicitly support cancelling tasks.
The 'cancelled' status is now tracked by a Future that's passed to different asychronous tasks. That way it is possible to cancel all running tasks before browsing another Pillar node.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import asyncio
|
||||
import traceback
|
||||
import concurrent.futures
|
||||
import logging
|
||||
|
||||
import bpy
|
||||
@@ -9,6 +10,20 @@ import bpy
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup_asyncio_executor():
|
||||
"""Sets up AsyncIO to run on a single thread.
|
||||
|
||||
This ensures that only one Pillar HTTP call is performed at the same time. Other
|
||||
calls that could be performed in parallel are queued, and thus we can
|
||||
reliably cancel them.
|
||||
"""
|
||||
|
||||
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.set_default_executor(executor)
|
||||
# loop.set_debug(True)
|
||||
|
||||
|
||||
def kick_async_loop(*args):
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
|
Reference in New Issue
Block a user