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:
2016-03-15 14:05:54 +01:00
parent 0174c28075
commit 5e237bea22
4 changed files with 174 additions and 56 deletions

View File

@@ -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()