File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -383,11 +383,11 @@ def test_code_object_events_dispatched(self):
383383 del co3
384384 self .assert_event_counts (2 , 2 , 1 , 1 )
385385
386- # verify counts remain as they were after both watchers are cleared
386+ # verify counts are reset and don't change after both watchers are cleared
387387 co4 = _testcapi .code_newempty ("test_watchers" , "dummy4" , 0 )
388- self .assert_event_counts (2 , 2 , 1 , 1 )
388+ self .assert_event_counts (0 , 0 , 0 , 0 )
389389 del co4
390- self .assert_event_counts (2 , 2 , 1 , 1 )
390+ self .assert_event_counts (0 , 0 , 0 , 0 )
391391
392392 def test_clear_out_of_range_watcher_id (self ):
393393 with self .assertRaisesRegex (ValueError , r"Invalid code watcher ID -1" ):
Original file line number Diff line number Diff line change @@ -325,9 +325,13 @@ add_code_watcher(PyObject *self, PyObject *which_watcher)
325325 long which_l = PyLong_AsLong (which_watcher );
326326 if (which_l == 0 ) {
327327 watcher_id = PyCode_AddWatcher (first_code_object_callback );
328+ num_code_object_created_events [0 ] = 0 ;
329+ num_code_object_destroyed_events [0 ] = 0 ;
328330 }
329331 else if (which_l == 1 ) {
330332 watcher_id = PyCode_AddWatcher (second_code_object_callback );
333+ num_code_object_created_events [1 ] = 0 ;
334+ num_code_object_destroyed_events [1 ] = 0 ;
331335 }
332336 else {
333337 return NULL ;
@@ -346,6 +350,11 @@ clear_code_watcher(PyObject *self, PyObject *watcher_id)
346350 if (PyCode_ClearWatcher (watcher_id_l ) < 0 ) {
347351 return NULL ;
348352 }
353+ // reset static events counters
354+ if (watcher_id_l >= 0 && watcher_id_l < NUM_CODE_WATCHERS ) {
355+ num_code_object_created_events [watcher_id_l ] = 0 ;
356+ num_code_object_destroyed_events [watcher_id_l ] = 0 ;
357+ }
349358 Py_RETURN_NONE ;
350359}
351360
You can’t perform that action at this time.
0 commit comments