mirror of
https://github.com/wassname/ray.git
synced 2026-06-27 21:38:18 +08:00
Switch debugger to sockets and support unicode (#13004)
This commit is contained in:
@@ -6,7 +6,6 @@ import logging
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from telnetlib import Telnet
|
||||
import time
|
||||
import urllib
|
||||
import urllib.parse
|
||||
@@ -172,8 +171,7 @@ def continue_debug_session():
|
||||
ray.experimental.internal_kv._internal_kv_del(key)
|
||||
return
|
||||
host, port = session["pdb_address"].split(":")
|
||||
with Telnet(host, int(port)) as tn:
|
||||
tn.interact()
|
||||
ray.util.rpdb.connect_pdb_client(host, int(port))
|
||||
ray.experimental.internal_kv._internal_kv_del(key)
|
||||
continue_debug_session()
|
||||
return
|
||||
@@ -215,8 +213,7 @@ def debug(address):
|
||||
ray.experimental.internal_kv._internal_kv_get(
|
||||
active_sessions[index]))
|
||||
host, port = session["pdb_address"].split(":")
|
||||
with Telnet(host, int(port)) as tn:
|
||||
tn.interact()
|
||||
ray.util.rpdb.connect_pdb_client(host, int(port))
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
||||
@@ -44,6 +44,7 @@ def test_ray_debugger_commands(shutdown_only):
|
||||
|
||||
@ray.remote
|
||||
def f():
|
||||
"""We support unicode too: 🐛"""
|
||||
ray.util.pdb.set_trace()
|
||||
|
||||
result1 = f.remote()
|
||||
@@ -55,6 +56,10 @@ def test_ray_debugger_commands(shutdown_only):
|
||||
p.expect("Enter breakpoint index or press enter to refresh: ")
|
||||
p.sendline("0")
|
||||
p.expect("-> ray.util.pdb.set_trace()")
|
||||
p.sendline("ll")
|
||||
# Cannot use the 🐛 symbol here because pexpect doesn't support
|
||||
# unicode, but this test also does nicely:
|
||||
p.expect("unicode")
|
||||
p.sendline("c")
|
||||
p.expect("Enter breakpoint index or press enter to refresh: ")
|
||||
p.sendline("0")
|
||||
|
||||
@@ -8,6 +8,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import select
|
||||
import socket
|
||||
import sys
|
||||
import uuid
|
||||
@@ -234,3 +235,27 @@ def set_trace(breakpoint_uuid=None):
|
||||
def post_mortem():
|
||||
rdb = connect_ray_pdb(None, None, False, None)
|
||||
rdb.post_mortem()
|
||||
|
||||
|
||||
def connect_pdb_client(host, port):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((host, port))
|
||||
|
||||
while True:
|
||||
# Get the list of sockets which are readable.
|
||||
read_sockets, write_sockets, error_sockets = select.select(
|
||||
[sys.stdin, s], [], [])
|
||||
|
||||
for sock in read_sockets:
|
||||
if sock == s:
|
||||
# Incoming message from remote debugger.
|
||||
data = sock.recv(4096)
|
||||
if not data:
|
||||
return
|
||||
else:
|
||||
sys.stdout.write(data.decode())
|
||||
sys.stdout.flush()
|
||||
else:
|
||||
# User entered a message.
|
||||
msg = sys.stdin.readline()
|
||||
s.send(msg.encode())
|
||||
|
||||
Reference in New Issue
Block a user