Commit 8f47cf26 authored by Alexander Koshevoy's avatar Alexander Koshevoy
Browse files

PY-24191 Use dictionary for handling CMD_PROCESS_CREATED_MSG_RECEIVED messages in predictable way

parent 1f83f996
Showing with 30 additions and 24 deletions
+30 -24
......@@ -710,10 +710,11 @@ def process_net_command(py_db, cmd_id, seq, text):
pydevd_dont_trace.trace_filter(mode)
elif cmd_id == CMD_PROCESS_CREATED_MSG_RECEIVED:
event = py_db.process_created_msg_received_event
original_seq = int(text)
event = py_db.process_created_msg_received_events.pop(original_seq, None)
if event:
py_db.process_created_msg_received_event = None
event.set()
else:
......
......@@ -281,7 +281,8 @@ class PyDB:
# this flag disables frame evaluation even if it's available
self.do_not_use_frame_eval = False
self.process_created_msg_received_event = None
# sequence id of `CMD_PROCESS_CREATED` command -> threading.Event
self.process_created_msg_received_events = dict()
# the role PyDB plays in the communication with IDE
self.communication_role = None
......@@ -759,27 +760,24 @@ class PyDB:
self.writer.add_command(cmd)
def send_process_will_be_substituted(self):
"""Sends a message that a new process is going to be created.
When `PyDB` works in server mode this method also waits for the
"""When `PyDB` works in server mode this method sends a message that a
new process is going to be created. After that it waits for the
response from the IDE to be sure that the IDE received this message.
Waiting for the response is required because the current process might
become substituted before it actually sends the message and the IDE
will not try to connect to `PyDB` in this case.
Waiting of the response in server mode is required because the current
process might become substituted before it actually sends the message
and the IDE will not try to connect to `PyDB` in this case.
Waiting of the response in client mode is not required because the
When `PyDB` works in client mode this method does nothing because the
substituted process will try to connect to the IDE itself.
"""
event = None
if self.communication_role == CommunicationRole.SERVER:
cmd = self.cmd_factory.make_process_created_message()
# register event before putting command to the message queue
event = threading.Event()
self.process_created_msg_received_event = event
cmd = self.cmd_factory.make_process_created_message()
self.writer.add_command(cmd)
if self.communication_role == CommunicationRole.SERVER:
self.process_created_msg_received_events[cmd.seq] = event
# put command to the message queue
self.writer.add_command(cmd)
# wait for the reply
event.wait()
def set_next_statement(self, frame, event, func_name, next_line):
......
......@@ -82,9 +82,9 @@ public class ClientModeMultiProcessDebugger implements ProcessDebugger {
private RemoteDebugger tryToConnectRemoteDebugger() throws Exception {
RemoteDebugger debugger = new RemoteDebugger(myDebugProcess, myHost, myPort) {
@Override
protected void onProcessCreatedEvent() {
protected void onProcessCreatedEvent(int commandSequence) {
try {
ProcessCreatedMsgReceivedCommand command = new ProcessCreatedMsgReceivedCommand(this);
ProcessCreatedMsgReceivedCommand command = new ProcessCreatedMsgReceivedCommand(this, commandSequence);
command.execute();
}
catch (PyDebuggerException e) {
......
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.debugger.pydev
class ProcessCreatedMsgReceivedCommand(debugger: RemoteDebugger) : AbstractCommand<Void>(debugger, PROCESS_CREATED_MSG_RECEIVED) {
override fun buildPayload(payload: Payload) = Unit
/**
* @param commandSequence the original [ProcessCreatedCommand] sequence number
*/
class ProcessCreatedMsgReceivedCommand(debugger: RemoteDebugger, private val commandSequence: Int)
: AbstractCommand<Void>(debugger, PROCESS_CREATED_MSG_RECEIVED) {
override fun buildPayload(payload: Payload) {
payload.add(commandSequence)
}
}
\ No newline at end of file
......@@ -546,7 +546,7 @@ public class RemoteDebugger implements ProcessDebugger {
myDebugProcess.consoleInputRequested(ProtocolParser.parseInputCommand(frame.getPayload()));
}
else if (ProcessCreatedCommand.isProcessCreatedCommand(frame.getCommand())) {
onProcessCreatedEvent();
onProcessCreatedEvent(frame.getSequence());
}
else if (AbstractCommand.isShowWarningCommand(frame.getCommand())) {
myDebugProcess.showCythonWarning();
......@@ -736,7 +736,7 @@ public class RemoteDebugger implements ProcessDebugger {
}
}
protected void onProcessCreatedEvent() {
protected void onProcessCreatedEvent(int commandSequence) {
}
protected void fireCloseEvent() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment