Skip to content

Commit 9a1b256

Browse files
committed
optimize and some refactoring in debugger
1 parent 6e85788 commit 9a1b256

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

robotcode/debugger/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ async def run_robot(
177177

178178
exit_code = -1
179179
try:
180+
180181
exit_code = robot.run_cli(args, False)
181182
finally:
182183
if server.protocol.connected:
@@ -200,8 +201,6 @@ async def run_robot(
200201
except asyncio.CancelledError:
201202
pass
202203
finally:
203-
await run_coroutine_from_thread_async(server.protocol.wait_for_all_events_sended)
204-
205204
if server.protocol.connected:
206205
await run_coroutine_from_thread_async(server.protocol.terminate, loop=server.loop)
207206
try:

robotcode/debugger/server.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import asyncio
22
import os
3-
from typing import Any, List, Literal, Optional, Union
3+
from typing import Any, Literal, Optional, Union
44

55
from ..jsonrpc2.protocol import rpc_method
66
from ..jsonrpc2.server import JsonRPCServer, JsonRpcServerMode, TcpParams
77
from ..utils import async_tools
8-
from ..utils.async_tools import run_coroutine_from_thread_as_future_async
8+
from ..utils.async_tools import run_coroutine_from_thread
99
from ..utils.logging import LoggingDescriptor
1010
from .dap_types import (
1111
ConfigurationDoneArguments,
@@ -66,29 +66,12 @@ def __init__(self) -> None:
6666

6767
self._received_configuration_done_event = async_tools.Event()
6868
self._received_configuration_done = False
69-
self._sended_events: List[asyncio.Future[None]] = []
7069

7170
Debugger.instance().send_event.add(self.on_debugger_send_event)
7271

7372
def on_debugger_send_event(self, sender: Any, event: Event) -> None:
74-
def remove_future(future: "asyncio.Future[None]") -> None:
75-
self._sended_events.remove(future)
76-
7773
if self._loop is not None:
78-
future = run_coroutine_from_thread_as_future_async(self.send_event_async, event, loop=self._loop)
79-
self._sended_events.append(future)
80-
future.add_done_callback(remove_future)
81-
82-
async def wait_for_all_events_sended(self, timeout: float = 5) -> bool:
83-
async def wait() -> bool:
84-
while True:
85-
if self._sended_events:
86-
await asyncio.sleep(0.01)
87-
else:
88-
return True
89-
return False
90-
91-
return await asyncio.wait_for(asyncio.create_task(wait()), timeout)
74+
run_coroutine_from_thread(self.send_event_async, event, loop=self._loop)
9275

9376
@property
9477
def connected(self) -> bool:

robotcode/utils/async_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def run_coroutine_from_thread(
739739
return result.cfuture.result()
740740

741741

742-
def run_coroutine_from_thread_as_future_async(
742+
def run_coroutine_from_thread_as_future(
743743
func: Callable[..., Coroutine[Any, Any, _T]],
744744
*args: Any,
745745
loop: Optional[asyncio.AbstractEventLoop] = None,
@@ -760,7 +760,7 @@ async def run_coroutine_from_thread_async(
760760
if loop is None:
761761
loop = asyncio.get_running_loop()
762762

763-
return await run_coroutine_from_thread_as_future_async(func, *args, loop=loop, **kwargs)
763+
return await run_coroutine_from_thread_as_future(func, *args, loop=loop, **kwargs)
764764

765765

766766
def wrap_sub_future(

0 commit comments

Comments
 (0)