@@ -28,6 +28,7 @@ class PugdebugDebugger(QObject):
2828 current_file = ''
2929 current_line = 0
3030
31+ server_stopped_signal = pyqtSignal ()
3132 debugging_started_signal = pyqtSignal ()
3233 debugging_post_start_signal = pyqtSignal ()
3334 debugging_stopped_signal = pyqtSignal ()
@@ -58,8 +59,8 @@ def __init__(self):
5859 def connect_server_signals (self ):
5960 """Connect server signals to slots
6061 """
61- self .server .server_connected_signal .connect (
62- self .handle_server_connected
62+ self .server .new_connection_established_signal .connect (
63+ self .handle_new_connection_established
6364 )
6465 self .server .server_stopped_signal .connect (
6566 self .handle_server_stopped
@@ -128,21 +129,15 @@ def connect_connection_signals(self, connection):
128129 self .handle_connection_error
129130 )
130131
131- def cleanup (self ):
132- """Cleanup debugger when it's done
132+ def cleanup_current_connection (self ):
133+ """Cleanup the current debugger connection
133134
134- If there is an active connection, disconnect from it and clear
135- all the remaining connections.
136-
137- Stop the server from listening.
135+ If there is an active connection, disconnect from it.
138136
139137 Clean up attributes.
140138 """
141139 if self .is_connected ():
142140 self .current_connection .disconnect ()
143- self .connections .clear ()
144-
145- self .server .stop ()
146141
147142 self .current_connection = None
148143 self .step_result = ''
@@ -159,14 +154,12 @@ def has_pending_connections(self):
159154 """
160155 return len (self .connections ) > 0
161156
162- def start_debug (self ):
163- """Start a debugging session
164-
165- If the server is not connected, connect it.
157+ def start_listening (self ):
158+ """Start listening to new connections
166159 """
167- self .server .connect ()
160+ self .server .start_listening ()
168161
169- def handle_server_connected (self , connection ):
162+ def handle_new_connection_established (self , connection ):
170163 """Handle when the server establishes a new connection
171164
172165 Connect the signals for the new connection.
@@ -180,9 +173,9 @@ def handle_server_connected(self, connection):
180173 self .connections .append (connection )
181174
182175 if not self .is_connected ():
183- self .start_new_connection ()
176+ self .start_debugging_new_connection ()
184177
185- def start_new_connection (self ):
178+ def start_debugging_new_connection (self ):
186179 """Start a new connection
187180
188181 Get the first (oldest) connection from the queue, set it's init
@@ -208,15 +201,20 @@ def handle_post_start(self):
208201 """
209202 self .debugging_post_start_signal .emit ()
210203
211- def handle_server_stopped (self ):
212- """Handle when the server is stopped
204+ def stop_listening (self ):
205+ """Stop listening for new connections
213206
214- If the current connection is terminated, cleanup the debugging
215- session and emit the debugging stopped signal.
207+ Clear connections queue, stop debugging the current connection.
216208 """
217- if not self .is_connected ():
218- self .cleanup ()
219- self .debugging_stopped_signal .emit ()
209+ self .connections .clear ()
210+ self .stop_debug ()
211+
212+ self .server .stop_listening ()
213+
214+ def handle_server_stopped (self ):
215+ """Handle when the server stops listening to new connections
216+ """
217+ self .server_stopped_signal .emit ()
220218
221219 def stop_debug (self ):
222220 """Stop a debugging session
@@ -226,8 +224,6 @@ def stop_debug(self):
226224 """
227225 if self .is_connected ():
228226 self .current_connection .stop ()
229- else :
230- self .server .stop ()
231227
232228 def detach_debug (self ):
233229 """Detach the current connection
@@ -240,13 +236,12 @@ def handle_stopped(self):
240236
241237 If there are pending connections, start a new one.
242238
243- Otherwise clean up and emit a server stopped signal.
239+ Otherwise emit a debugging stopped signal.
244240 """
245241 if self .has_pending_connections ():
246- self .start_new_connection ()
242+ self .start_debugging_new_connection ()
247243 else :
248- self .cleanup ()
249-
244+ self .cleanup_current_connection ()
250245 self .debugging_stopped_signal .emit ()
251246
252247 def run_debug (self ):
0 commit comments