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):
383
383
del co3
384
384
self .assert_event_counts (2 , 2 , 1 , 1 )
385
385
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
387
387
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 )
389
389
del co4
390
- self .assert_event_counts (2 , 2 , 1 , 1 )
390
+ self .assert_event_counts (0 , 0 , 0 , 0 )
391
391
392
392
def test_clear_out_of_range_watcher_id (self ):
393
393
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)
325
325
long which_l = PyLong_AsLong (which_watcher );
326
326
if (which_l == 0 ) {
327
327
watcher_id = PyCode_AddWatcher (first_code_object_callback );
328
+ num_code_object_created_events [0 ] = 0 ;
329
+ num_code_object_destroyed_events [0 ] = 0 ;
328
330
}
329
331
else if (which_l == 1 ) {
330
332
watcher_id = PyCode_AddWatcher (second_code_object_callback );
333
+ num_code_object_created_events [1 ] = 0 ;
334
+ num_code_object_destroyed_events [1 ] = 0 ;
331
335
}
332
336
else {
333
337
return NULL ;
@@ -346,6 +350,11 @@ clear_code_watcher(PyObject *self, PyObject *watcher_id)
346
350
if (PyCode_ClearWatcher (watcher_id_l ) < 0 ) {
347
351
return NULL ;
348
352
}
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
+ }
349
358
Py_RETURN_NONE ;
350
359
}
351
360
You can’t perform that action at this time.
0 commit comments