Skip to content

Commit

Permalink
isolated ThreadPoolExecutor for firmware update speed up (#11898)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoegenburg committed Dec 15, 2022
1 parent 0f0ad46 commit f36eea1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hardware/opentrons_hardware/drivers/can_bus/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio
import platform
from typing import Optional, Union, Dict, Any
import concurrent.futures

from can import Notifier, Bus, AsyncBufferedReader, Message

Expand Down Expand Up @@ -49,6 +50,7 @@ def __init__(self, bus: Bus, loop: asyncio.AbstractEventLoop) -> None:
self._loop = loop
self._reader = AsyncBufferedReader(loop=loop)
self._notifier = Notifier(bus=self._bus, listeners=[self._reader], loop=loop)
self._executor = concurrent.futures.ThreadPoolExecutor(max_workers=5)

@classmethod
async def build(
Expand Down Expand Up @@ -113,7 +115,7 @@ async def send(self, message: CanMessage) -> None:
is_fd=True,
data=message.data,
)
await self._loop.run_in_executor(None, self._bus.send, m)
await self._loop.run_in_executor(self._executor, self._bus.send, m)

async def read(self) -> CanMessage:
"""Read a message.
Expand Down

0 comments on commit f36eea1

Please sign in to comment.