From 510ce942a9bba2e35defb8e799a4a7f68dc0601e Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Tue, 26 Mar 2019 20:16:42 -0700 Subject: [PATCH] Remove 'yield' from some request handlers (#5) * Remove 'yield' from some request handlers * Fix json notify request --- src/ptvsd/wrapper.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ptvsd/wrapper.py b/src/ptvsd/wrapper.py index 7429c892a..0082b0255 100644 --- a/src/ptvsd/wrapper.py +++ b/src/ptvsd/wrapper.py @@ -464,7 +464,12 @@ def pydevd_notify(self, cmd_id, args, is_json=False): else: seq, s = self.make_packet(cmd_id, args) with self.lock: - os.write(self.pipe_w, s.encode('utf8')) + as_bytes = s + if not isinstance(as_bytes, bytes): + as_bytes = as_bytes.encode('utf-8') + if is_json: + os.write(self.pipe_w, ('Content-Length:%s\r\n\r\n' % (len(as_bytes),)).encode('ascii')) + os.write(self.pipe_w, as_bytes) def pydevd_request(self, loop, cmd_id, args, is_json=False): ''' @@ -1696,8 +1701,8 @@ def on_pause(self, request, args): pydevd_request['arguments'] = {'threadId': '*'} # Always suspend all threads. - yield self.pydevd_request(pydevd_comm.CMD_THREAD_SUSPEND, - pydevd_request, is_json=True) + self.pydevd_request(pydevd_comm.CMD_THREAD_SUSPEND, + pydevd_request, is_json=True) self.send_response(request) @async_handler @@ -1711,8 +1716,8 @@ def on_continue(self, request, args): pydevd_request['arguments'] = {'threadId': '*'} # Always continue all threads. - yield self.pydevd_request(pydevd_comm.CMD_THREAD_RUN, - pydevd_request, is_json=True) + self.pydevd_request(pydevd_comm.CMD_THREAD_RUN, + pydevd_request, is_json=True) self.send_response(request, allThreadsContinued=True) @async_handler @@ -1725,7 +1730,7 @@ def on_next(self, request, args): pydevd_request['arguments']['threadId'] = pyd_tid cmd_id = pydevd_comm.CMD_STEP_OVER - yield self.pydevd_request(cmd_id, pydevd_request, is_json=True) + self.pydevd_request(cmd_id, pydevd_request, is_json=True) self.send_response(request) @async_handler @@ -1738,7 +1743,7 @@ def on_stepIn(self, request, args): pydevd_request['arguments']['threadId'] = pyd_tid cmd_id = pydevd_comm.CMD_STEP_INTO - yield self.pydevd_request(cmd_id, pydevd_request, is_json=True) + self.pydevd_request(cmd_id, pydevd_request, is_json=True) self.send_response(request) @async_handler @@ -1751,7 +1756,7 @@ def on_stepOut(self, request, args): pydevd_request['arguments']['threadId'] = pyd_tid cmd_id = pydevd_comm.CMD_STEP_RETURN - yield self.pydevd_request(cmd_id, pydevd_request, is_json=True) + self.pydevd_request(cmd_id, pydevd_request, is_json=True) self.send_response(request) @async_handler