@@ -97,17 +97,34 @@ cdef class Handle:
97
97
cdef _cancel(self ):
98
98
self .cancelled = 1
99
99
self .callback = NULL
100
- self .arg1 = self . arg2 = self .arg3 = self .arg4 = None
100
+ self .arg2 = self .arg3 = self .arg4 = None
101
101
102
102
# Public API
103
103
104
104
def __repr__ (self ):
105
+ info = [self .__class__.__name__ ]
106
+
105
107
if self .cancelled:
106
- return ' <Handle cancelled {:#x}>' .format(id (self ))
108
+ info.append(' cancelled' )
109
+
110
+ if self .cb_type == 1 :
111
+ func = self .arg1
112
+ if hasattr (func, ' __qualname__' ):
113
+ cb_name = getattr (func, ' __qualname__' )
114
+ elif hasattr (func, ' __name__' ):
115
+ cb_name = getattr (func, ' __name__' )
116
+ else :
117
+ cb_name = repr (func)
118
+
119
+ info.append(cb_name)
107
120
else :
108
- return ' <Handle {!r} {:#x}>' .format(
109
- self .arg1 if self .cb_type == 1 else self .meth_name,
110
- id (self ))
121
+ info.append(self .meth_name)
122
+
123
+ if self ._source_traceback is not None :
124
+ frame = self ._source_traceback[- 1 ]
125
+ info.append(' created at {}:{}' .format(frame[0 ], frame[1 ]))
126
+
127
+ return ' <' + ' ' .join(info) + ' >'
111
128
112
129
def cancel (self ):
113
130
self ._cancel()
@@ -177,6 +194,8 @@ cdef class TimerHandle:
177
194
if old_exec_py_code == 1 :
178
195
raise RuntimeError (' Python exec-mode before TimerHandle._run' )
179
196
self .loop._executing_py_code = 1
197
+ if self .loop._debug:
198
+ started = time_monotonic()
180
199
try :
181
200
if args is not None :
182
201
callback(* args)
@@ -193,17 +212,40 @@ cdef class TimerHandle:
193
212
context[' source_traceback' ] = self ._source_traceback
194
213
195
214
self .loop.call_exception_handler(context)
215
+ else :
216
+ if self .loop._debug:
217
+ delta = time_monotonic() - started
218
+ if delta > self .loop.slow_callback_duration:
219
+ aio_logger.warning(
220
+ ' Executing %r took %.3f seconds' ,
221
+ self , delta)
196
222
finally :
197
223
self .loop._executing_py_code = old_exec_py_code
198
224
Py_DECREF(self )
199
225
200
226
# Public API
201
227
202
228
def __repr__ (self ):
229
+ info = [self .__class__.__name__ ]
230
+
203
231
if self .closed:
204
- return ' <TimerHandle cancelled {:#x}>' .format(id (self ))
232
+ info.append(' cancelled' )
233
+
234
+ func = self .callback
235
+ if hasattr (func, ' __qualname__' ):
236
+ cb_name = getattr (func, ' __qualname__' )
237
+ elif hasattr (func, ' __name__' ):
238
+ cb_name = getattr (func, ' __name__' )
205
239
else :
206
- return ' <TimerHandle {!r} {:#x}>' .format(self .callback, id (self ))
240
+ cb_name = repr (func)
241
+
242
+ info.append(cb_name)
243
+
244
+ if self ._source_traceback is not None :
245
+ frame = self ._source_traceback[- 1 ]
246
+ info.append(' created at {}:{}' .format(frame[0 ], frame[1 ]))
247
+
248
+ return ' <' + ' ' .join(info) + ' >'
207
249
208
250
def cancel (self ):
209
251
self ._cancel()
0 commit comments