@@ -97,17 +97,34 @@ cdef class Handle:
9797 cdef _cancel(self ):
9898 self .cancelled = 1
9999 self .callback = NULL
100- self .arg1 = self . arg2 = self .arg3 = self .arg4 = None
100+ self .arg2 = self .arg3 = self .arg4 = None
101101
102102 # Public API
103103
104104 def __repr__ (self ):
105+ info = [self .__class__.__name__ ]
106+
105107 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)
107120 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) + ' >'
111128
112129 def cancel (self ):
113130 self ._cancel()
@@ -177,6 +194,8 @@ cdef class TimerHandle:
177194 if old_exec_py_code == 1 :
178195 raise RuntimeError (' Python exec-mode before TimerHandle._run' )
179196 self .loop._executing_py_code = 1
197+ if self .loop._debug:
198+ started = time_monotonic()
180199 try :
181200 if args is not None :
182201 callback(* args)
@@ -193,17 +212,40 @@ cdef class TimerHandle:
193212 context[' source_traceback' ] = self ._source_traceback
194213
195214 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)
196222 finally :
197223 self .loop._executing_py_code = old_exec_py_code
198224 Py_DECREF(self )
199225
200226 # Public API
201227
202228 def __repr__ (self ):
229+ info = [self .__class__.__name__ ]
230+
203231 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__' )
205239 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) + ' >'
207249
208250 def cancel (self ):
209251 self ._cancel()
0 commit comments