Skip to content

Commit

Permalink
✨ single process error fixed but this commit is to remove lator
Browse files Browse the repository at this point in the history
  • Loading branch information
MeditationDuck committed Nov 29, 2024
1 parent 3e40eff commit fc05b42
Show file tree
Hide file tree
Showing 6 changed files with 473 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"wake.compiler.solc.remappings": []
}
2 changes: 1 addition & 1 deletion wake/development/chain_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def launch(
args += ["-k", hardfork]

console.print(f"Launching {' '.join(args)}")
process = subprocess.Popen(args, stdout=subprocess.DEVNULL)
process = subprocess.Popen(args, stdout=subprocess.DEVNULL, start_new_session=True)

try:
start = time.perf_counter()
Expand Down
41 changes: 27 additions & 14 deletions wake/development/json_rpc/communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .http import HttpProtocol
from .ipc import IpcProtocol
from .websocket import WebsocketProtocol
import signal

logger = get_logger(__name__)

Expand All @@ -24,6 +25,7 @@ class JsonRpcCommunicator:
_protocol: ProtocolAbc
_request_id: int
_connected: bool
_interrupt_received: bool

def __init__(self, config: WakeConfig, uri: str):
if uri.startswith(("http://", "https://")):
Expand All @@ -37,7 +39,7 @@ def __init__(self, config: WakeConfig, uri: str):

self._request_id = 0
self._connected = False

self._interrupt_received = False
def __enter__(self):
self._protocol.__enter__()
self._connected = True
Expand All @@ -51,18 +53,29 @@ def __exit__(self, exc_type, exc_value, traceback):
def connected(self) -> bool:
return self._connected

def _signal_handler(self, signal_number, frame):
self._interrupt_received = True

def send_request(self, method_name: str, params: Optional[List] = None) -> Any:
post_data = {
"jsonrpc": "2.0",
"method": method_name,
"params": params if params is not None else [],
"id": self._request_id,
}
logger.info(f"Sending request:\n{post_data}")
self._request_id += 1
# Ignore SIGINT during request processing
original_handler = signal.signal(signal.SIGINT, self._signal_handler)
try:
post_data = {
"jsonrpc": "2.0",
"method": method_name,
"params": params if params is not None else [],
"id": self._request_id,
}
logger.info(f"Sending request:\n{post_data}")
self._request_id += 1

response = self._protocol.send_recv(json.dumps(post_data))
logger.info(f"Received response:\n{json.dumps(response)}")
if "error" in response:
raise JsonRpcError(response["error"])
return response["result"]
response = self._protocol.send_recv(json.dumps(post_data))
logger.info(f"Received response:\n{json.dumps(response)}")
if "error" in response:
raise JsonRpcError(response["error"])
return response["result"]
finally:
# Restore the original SIGINT handler
signal.signal(signal.SIGINT, original_handler)
if self._interrupt_received:
raise KeyboardInterrupt
Loading

0 comments on commit fc05b42

Please sign in to comment.