Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deltachat-rpc-client): add the Lock around request ID #4947

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions deltachat-rpc-client/src/deltachat_rpc_client/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
import sys
from queue import Queue
from threading import Event, Thread
from threading import Event, Lock, Thread
from typing import Any, Dict, Optional


Expand All @@ -24,6 +24,7 @@ def __init__(self, accounts_dir: Optional[str] = None, **kwargs):
self._kwargs = kwargs
self.process: subprocess.Popen
self.id: int
self.id_lock: Lock
self.event_queues: Dict[int, Queue]
# Map from request ID to `threading.Event`.
self.request_events: Dict[int, Event]
Expand Down Expand Up @@ -55,6 +56,7 @@ def start(self) -> None:
**self._kwargs,
)
self.id = 0
self.id_lock = Lock()
self.event_queues = {}
self.request_events = {}
self.request_results = {}
Expand Down Expand Up @@ -143,14 +145,16 @@ def wait_for_event(self, account_id: int) -> Optional[dict]:

def __getattr__(self, attr: str):
def method(*args) -> Any:
self.id_lock.acquire()
self.id += 1
request_id = self.id
self.id_lock.release()

request = {
"jsonrpc": "2.0",
"method": attr,
"params": args,
"id": self.id,
"id": request_id,
}
event = Event()
self.request_events[request_id] = event
Expand Down
Loading