robotcode-jsonrpc2 0.64.1__tar.gz → 0.66.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: robotcode-jsonrpc2
3
- Version: 0.64.1
3
+ Version: 0.66.0
4
4
  Summary: JSONRPC Server for RobotCode
5
5
  Project-URL: Homepage, https://robotcode.io
6
6
  Project-URL: Donate, https://github.com/sponsors/d-biehl
@@ -25,7 +25,7 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
25
25
  Classifier: Topic :: Utilities
26
26
  Classifier: Typing :: Typed
27
27
  Requires-Python: >=3.8
28
- Requires-Dist: robotcode-core==0.64.1
28
+ Requires-Dist: robotcode-core==0.66.0
29
29
  Description-Content-Type: text/markdown
30
30
 
31
31
  # robotcode-jsonrpc2
@@ -25,7 +25,7 @@ classifiers = [
25
25
  "Framework :: Robot Framework",
26
26
  "Framework :: Robot Framework :: Tool",
27
27
  ]
28
- dependencies = ["robotcode-core==0.64.1"]
28
+ dependencies = ["robotcode-core==0.66.0"]
29
29
  dynamic = ["version"]
30
30
 
31
31
  [project.urls]
@@ -0,0 +1 @@
1
+ __version__ = "0.66.0"
@@ -1,11 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
+ import concurrent.futures
4
5
  import inspect
5
6
  import json
6
7
  import re
7
8
  import threading
8
- import time
9
9
  import weakref
10
10
  from abc import ABC, abstractmethod
11
11
  from collections import OrderedDict
@@ -36,7 +36,6 @@ from typing import (
36
36
  from robotcode.core.async_tools import (
37
37
  HasThreaded,
38
38
  async_event,
39
- create_sub_future,
40
39
  create_sub_task,
41
40
  run_coroutine_in_thread,
42
41
  )
@@ -336,7 +335,7 @@ class RpcRegistry:
336
335
 
337
336
 
338
337
  class SendedRequestEntry(NamedTuple):
339
- future: asyncio.Future[Any]
338
+ future: concurrent.futures.Future[Any]
340
339
  result_type: Optional[Type[Any]]
341
340
 
342
341
 
@@ -546,9 +545,9 @@ class JsonRPCProtocol(JsonRPCProtocolBase):
546
545
  method: str,
547
546
  params: Optional[Any] = None,
548
547
  return_type_or_converter: Optional[Type[_TResult]] = None,
549
- ) -> asyncio.Future[Optional[_TResult]]:
548
+ ) -> concurrent.futures.Future[_TResult]:
550
549
  with self._sended_request_lock:
551
- result: asyncio.Future[Optional[_TResult]] = create_sub_future()
550
+ result: concurrent.futures.Future[_TResult] = concurrent.futures.Future()
552
551
  self._sended_request_count += 1
553
552
  id = self._sended_request_count
554
553
 
@@ -559,13 +558,13 @@ class JsonRPCProtocol(JsonRPCProtocolBase):
559
558
 
560
559
  return result
561
560
 
562
- async def send_request_async(
561
+ def send_request_async(
563
562
  self,
564
563
  method: str,
565
564
  params: Optional[Any] = None,
566
565
  return_type: Optional[Type[_TResult]] = None,
567
- ) -> Optional[_TResult]:
568
- return await self.send_request(method, params, return_type)
566
+ ) -> asyncio.Future[_TResult]:
567
+ return asyncio.wrap_future(self.send_request(method, params, return_type))
569
568
 
570
569
  @__logger.call
571
570
  def send_notification(self, method: str, params: Any) -> None:
@@ -590,44 +589,17 @@ class JsonRPCProtocol(JsonRPCProtocolBase):
590
589
 
591
590
  try:
592
591
  if not entry.future.done():
593
- res = None
594
- if message.result is not None:
595
- res = from_dict(message.result, entry.result_type)
596
- if entry.future.get_loop() == asyncio.get_running_loop():
597
- entry.future.set_result(res)
598
- else:
599
- if entry.future.get_loop().is_running():
600
-
601
- def set_result(f: asyncio.Future[Any], r: Any, ev: threading.Event) -> None:
602
- try:
603
- if not f.done() and f.get_loop().is_running():
604
- f.set_result(r)
605
- finally:
606
- ev.set()
607
-
608
- done = threading.Event()
609
-
610
- entry.future.get_loop().call_soon_threadsafe(set_result, entry.future, res, done)
611
-
612
- start = time.monotonic()
613
- while not done.is_set():
614
- if time.monotonic() - start > 120:
615
- raise TimeoutError("Can't set future result.")
616
-
617
- await asyncio.sleep(0)
618
-
619
- else:
620
- self.__logger.warning(lambda: f"Response {entry!r} loop is not running.")
592
+ entry.future.set_result(
593
+ from_dict(message.result, entry.result_type) if message.result is not None else None
594
+ )
595
+ else:
596
+ self.__logger.warning(lambda: f"Response for {message} is already done.")
621
597
 
622
598
  except (SystemExit, KeyboardInterrupt):
623
599
  raise
624
600
  except BaseException as e:
625
601
  if not entry.future.done():
626
- if entry.future.get_loop() == asyncio.get_running_loop():
627
- entry.future.set_exception(e)
628
- else:
629
- if entry.future.get_loop().is_running():
630
- entry.future.get_loop().call_soon_threadsafe(entry.future.set_exception, e)
602
+ entry.future.set_exception(e)
631
603
 
632
604
  @__logger.call
633
605
  async def handle_error(self, message: JsonRPCError) -> None:
@@ -646,50 +618,17 @@ class JsonRPCProtocol(JsonRPCProtocolBase):
646
618
 
647
619
  try:
648
620
  if not entry.future.done():
649
- res = None
650
- if message.result is not None:
651
- res = from_dict(message.result, entry.result_type)
652
- if entry.future.get_loop() == asyncio.get_running_loop():
653
- entry.future.set_exception(
654
- JsonRPCErrorException(message.error.code, message.error.message, message.error.data)
655
- )
656
- else:
657
- if entry.future.get_loop().is_running():
658
-
659
- def set_result(f: asyncio.Future[Any], r: Any, ev: threading.Event) -> None:
660
- try:
661
- if not f.done() and f.get_loop().is_running():
662
- f.set_exception(
663
- JsonRPCErrorException(
664
- message.error.code, message.error.message, message.error.data
665
- )
666
- )
667
- finally:
668
- ev.set()
669
-
670
- done = threading.Event()
671
-
672
- entry.future.get_loop().call_soon_threadsafe(set_result, entry.future, res, done)
673
-
674
- start = time.monotonic()
675
- while not done.is_set():
676
- if time.monotonic() - start > 120:
677
- raise TimeoutError("Can't set future result.")
678
-
679
- await asyncio.sleep(0)
680
-
681
- else:
682
- self.__logger.warning(lambda: f"Response {entry!r} loop is not running.")
621
+ entry.future.set_exception(
622
+ JsonRPCErrorException(message.error.code, message.error.message, message.error.data)
623
+ )
624
+ else:
625
+ self.__logger.warning(lambda: f"Response for {message} is already done.")
683
626
 
684
627
  except (SystemExit, KeyboardInterrupt):
685
628
  raise
686
629
  except BaseException as e:
687
630
  if not entry.future.done():
688
- if entry.future.get_loop() == asyncio.get_running_loop():
689
- entry.future.set_exception(e)
690
- else:
691
- if entry.future.get_loop().is_running():
692
- entry.future.get_loop().call_soon_threadsafe(entry.future.set_exception, e)
631
+ entry.future.set_exception(e)
693
632
 
694
633
  @staticmethod
695
634
  def _convert_params(
@@ -1 +0,0 @@
1
- __version__ = "0.64.1"