translate concurrent.futures.CancelledError to asyncio.CancelledError

apparently cancelling something that is running in a thread leads to a different
exception class being raised...
This commit is contained in:
Michael Hudson-Doyle 2020-04-02 12:08:41 +13:00
parent 74d8280752
commit a03a336bd7
1 changed files with 5 additions and 1 deletions

View File

@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import asyncio
import concurrent.futures
import logging
@ -41,7 +42,10 @@ def schedule_task(coro, propagate_errors=True):
async def run_in_thread(func, *args):
loop = asyncio.get_event_loop()
try:
return await loop.run_in_executor(None, func, *args)
except concurrent.futures.CancelledError:
raise asyncio.CancelledError
class SingleInstanceTask: