File tree Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,11 @@ def tearDown(self):
87
87
gc .collect ()
88
88
gc .collect ()
89
89
90
+ self .assertEqual (
91
+ self .loop ._debug_uv_handles_total ,
92
+ self .loop ._debug_uv_handles_freed ,
93
+ 'not all uv_handle_t handles were freed' )
94
+
90
95
self .assertEqual (
91
96
self .loop ._debug_cb_handles_count , 0 ,
92
97
'not all callbacks (call_soon) are GCed' )
Original file line number Diff line number Diff line change @@ -68,6 +68,12 @@ cdef class UVHandle:
68
68
self ._free()
69
69
70
70
cdef inline _free(self ):
71
+ if self ._handle == NULL :
72
+ return
73
+
74
+ IF DEBUG:
75
+ self ._loop._debug_uv_handles_freed += 1
76
+
71
77
PyMem_Free(self ._handle)
72
78
self ._handle = NULL
73
79
@@ -101,6 +107,8 @@ cdef class UVHandle:
101
107
self ._handle.data = < void * > self
102
108
if self ._loop._debug:
103
109
self ._source_traceback = tb_extract_stack(sys_getframe(0 ))
110
+ IF DEBUG:
111
+ self ._loop._debug_uv_handles_total += 1
104
112
105
113
cdef inline _start_init(self , Loop loop):
106
114
IF DEBUG:
@@ -303,6 +311,13 @@ cdef void __uv_close_handle_cb(uv.uv_handle_t* handle) with gil:
303
311
if handle.data is NULL :
304
312
# The original UVHandle is long dead. Just free the mem of
305
313
# the uv_handle_t* handler.
314
+
315
+ IF DEBUG:
316
+ if handle.loop == NULL or handle.loop.data == NULL :
317
+ raise RuntimeError (
318
+ ' __uv_close_handle_cb: handle.loop is invalid' )
319
+ (< Loop> handle.loop.data)._debug_uv_handles_freed += 1
320
+
306
321
PyMem_Free(handle)
307
322
else :
308
323
h = < UVHandle> handle.data
Original file line number Diff line number Diff line change @@ -87,6 +87,9 @@ cdef class Loop:
87
87
readonly object _debug_handles_closed
88
88
readonly object _debug_handles_current
89
89
90
+ readonly uint64_t _debug_uv_handles_total
91
+ readonly uint64_t _debug_uv_handles_freed
92
+
90
93
readonly uint64_t _debug_cb_handles_total
91
94
readonly uint64_t _debug_cb_handles_count
92
95
readonly uint64_t _debug_cb_timer_handles_total
Original file line number Diff line number Diff line change @@ -98,6 +98,9 @@ cdef class Loop:
98
98
self ._debug_handles_closed = col_Counter()
99
99
self ._debug_handles_total = col_Counter()
100
100
101
+ self ._debug_uv_handles_total = 0
102
+ self ._debug_uv_handles_freed = 0
103
+
101
104
self ._debug_stream_read_cb_total = 0
102
105
self ._debug_stream_read_eof_total = 0
103
106
self ._debug_stream_read_errors_total = 0
@@ -871,6 +874,12 @@ cdef class Loop:
871
874
self ._debug_handles_total[name]))
872
875
print ()
873
876
877
+ print (' uv_handle_t (current: {}; freed: {}; total: {})' .format(
878
+ self ._debug_uv_handles_total - self ._debug_uv_handles_freed,
879
+ self ._debug_uv_handles_freed,
880
+ self ._debug_uv_handles_total))
881
+ print ()
882
+
874
883
print (' --- Streams debug info: ---' )
875
884
print (' Write errors: {}' .format(
876
885
self ._debug_stream_write_errors_total))
You can’t perform that action at this time.
0 commit comments