kalong 0.5.1__py3-none-any.whl → 0.5.2__py3-none-any.whl

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.
kalong/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """A new take on debugging"""
2
2
 
3
- __version__ = "0.5.1"
3
+ __version__ = "0.5.2"
4
4
  import os
5
5
  import sys
6
6
  from pathlib import Path
kalong/communication.py CHANGED
@@ -32,17 +32,15 @@ basicConfig(level=config.log_level)
32
32
 
33
33
 
34
34
  def exception_handler(loop, context):
35
- exception = context["exception"]
36
- message = context["message"]
37
- logging.error(f"Task failed, msg={message}, exception={exception}")
35
+ logging.error(f"Loop exit: {context}")
38
36
 
39
37
 
40
- def communicate(frame, event, arg):
38
+ def communicate(frame, event, arg, pending=None):
41
39
  loop = get_loop()
42
40
 
43
41
  loop.set_exception_handler(exception_handler)
44
42
  try:
45
- loop.run_until_complete(communication_loop(frame, event, arg))
43
+ loop.run_until_complete(communication_loop(frame, event, arg, pending))
46
44
  except asyncio.CancelledError:
47
45
  log.info("Loop got cancelled")
48
46
  die()
@@ -84,6 +82,7 @@ async def handle_message(ws, data, frame, event, arg):
84
82
 
85
83
  elif data["type"] == "SET_PROMPT" or data["type"] == "REFRESH_PROMPT":
86
84
  try:
85
+ step_frame = get_frame(frame, data.get("frame"), tb)
87
86
  eval_fun = (
88
87
  serialize_inspect_eval
89
88
  if data.get("command") == "inspect"
@@ -95,16 +94,27 @@ async def handle_message(ws, data, frame, event, arg):
95
94
  if data.get("command") == "recursive_debug"
96
95
  else serialize_answer
97
96
  )
98
- response = {
99
- "type": "SET_ANSWER",
100
- "key": data["key"],
101
- "command": data.get("command"),
102
- "frame": data.get("frame"),
103
- **eval_fun(
104
- data["prompt"],
105
- get_frame(frame, data.get("frame"), tb),
106
- ),
107
- }
97
+
98
+ def get_response():
99
+ return {
100
+ "type": "SET_ANSWER",
101
+ "key": data["key"],
102
+ "command": data.get("command"),
103
+ "frame": data.get("frame"),
104
+ **eval_fun(data["prompt"], step_frame),
105
+ }
106
+
107
+ if data.get("command") == "condition":
108
+ add_step("continue", step_frame, condition=get_response)
109
+ response = {
110
+ "type": "DO_COMMAND",
111
+ "command": "continue",
112
+ "frame": data.get("frame"),
113
+ "stop": True,
114
+ }
115
+ else:
116
+ response = get_response()
117
+
108
118
  except SetFrameError as e:
109
119
  frame = e.frame
110
120
  event = e.event
@@ -162,7 +172,7 @@ async def handle_message(ws, data, frame, event, arg):
162
172
  return response
163
173
 
164
174
 
165
- async def communication_loop(frame_, event_, arg_):
175
+ async def communication_loop(frame_, event_, arg_, pending=None):
166
176
  frame = frame_
167
177
  event = event_
168
178
  arg = arg_
@@ -178,6 +188,9 @@ async def communication_loop(frame_, event_, arg_):
178
188
  if existing:
179
189
  # If the socket is already opened we need to update client state
180
190
  await init(ws, frame, event, arg)
191
+ if pending:
192
+ # Start by sending pending message
193
+ await ws.send_json(pending)
181
194
  # Otherwise if it's new, just wait for HELLO to answer current state
182
195
 
183
196
  stop = False
kalong/config.py CHANGED
@@ -90,6 +90,9 @@ class Config:
90
90
  if value:
91
91
  setattr(self, name, type(name)(value))
92
92
 
93
+ if os.getenv("KALONG_PORT") and not os.getenv("KALONG_FRONT_PORT"):
94
+ self.front_port = self.port
95
+
93
96
  def get_args_for_server(self):
94
97
  yield "--server"
95
98
 
kalong/server.py CHANGED
@@ -109,6 +109,10 @@ async def websocket(request):
109
109
  return ws
110
110
 
111
111
 
112
+ def exception_handler(loop, context):
113
+ logging.error(f"Loop exit: {context}")
114
+
115
+
112
116
  def serve():
113
117
  app = web.Application()
114
118
  app["front"] = {}
@@ -116,4 +120,6 @@ def serve():
116
120
  app.on_shutdown.append(shutdown)
117
121
  app.router.add_get(r"/{side:(front|back)}/{origin}", websocket)
118
122
  app.router.add_static("/assets/", Path(__file__).parent / "static" / "assets")
119
- web.run_app(app, host=config.host, port=config.port, print=False)
123
+ loop = asyncio.get_event_loop()
124
+ loop.set_exception_handler(exception_handler)
125
+ web.run_app(app, host=config.host, port=config.port, print=False, loop=loop)