|
|
|
@ -528,12 +528,10 @@ class BaseEventLoop(events.AbstractEventLoop): |
|
|
|
|
|
|
|
Absolute time corresponds to the event loop's time() method. |
|
|
|
""" |
|
|
|
if (coroutines.iscoroutine(callback) |
|
|
|
or coroutines.iscoroutinefunction(callback)): |
|
|
|
raise TypeError("coroutines cannot be used with call_at()") |
|
|
|
self._check_closed() |
|
|
|
if self._debug: |
|
|
|
self._check_thread() |
|
|
|
self._check_callback(callback, 'call_at') |
|
|
|
timer = events.TimerHandle(when, callback, args, self) |
|
|
|
if timer._source_traceback: |
|
|
|
del timer._source_traceback[-1] |
|
|
|
@ -551,18 +549,27 @@ class BaseEventLoop(events.AbstractEventLoop): |
|
|
|
Any positional arguments after the callback will be passed to |
|
|
|
the callback when it is called. |
|
|
|
""" |
|
|
|
self._check_closed() |
|
|
|
if self._debug: |
|
|
|
self._check_thread() |
|
|
|
self._check_callback(callback, 'call_soon') |
|
|
|
handle = self._call_soon(callback, args) |
|
|
|
if handle._source_traceback: |
|
|
|
del handle._source_traceback[-1] |
|
|
|
return handle |
|
|
|
|
|
|
|
def _check_callback(self, callback, method): |
|
|
|
if (coroutines.iscoroutine(callback) or |
|
|
|
coroutines.iscoroutinefunction(callback)): |
|
|
|
raise TypeError( |
|
|
|
"coroutines cannot be used with {}()".format(method)) |
|
|
|
if not callable(callback): |
|
|
|
raise TypeError( |
|
|
|
'a callable object was expected by {}(), got {!r}'.format( |
|
|
|
method, callback)) |
|
|
|
|
|
|
|
|
|
|
|
def _call_soon(self, callback, args): |
|
|
|
if (coroutines.iscoroutine(callback) |
|
|
|
or coroutines.iscoroutinefunction(callback)): |
|
|
|
raise TypeError("coroutines cannot be used with call_soon()") |
|
|
|
self._check_closed() |
|
|
|
handle = events.Handle(callback, args, self) |
|
|
|
if handle._source_traceback: |
|
|
|
del handle._source_traceback[-1] |
|
|
|
@ -588,6 +595,9 @@ class BaseEventLoop(events.AbstractEventLoop): |
|
|
|
|
|
|
|
def call_soon_threadsafe(self, callback, *args): |
|
|
|
"""Like call_soon(), but thread-safe.""" |
|
|
|
self._check_closed() |
|
|
|
if self._debug: |
|
|
|
self._check_callback(callback, 'call_soon_threadsafe') |
|
|
|
handle = self._call_soon(callback, args) |
|
|
|
if handle._source_traceback: |
|
|
|
del handle._source_traceback[-1] |
|
|
|
@ -595,21 +605,9 @@ class BaseEventLoop(events.AbstractEventLoop): |
|
|
|
return handle |
|
|
|
|
|
|
|
def run_in_executor(self, executor, func, *args): |
|
|
|
if (coroutines.iscoroutine(func) |
|
|
|
or coroutines.iscoroutinefunction(func)): |
|
|
|
raise TypeError("coroutines cannot be used with run_in_executor()") |
|
|
|
self._check_closed() |
|
|
|
if isinstance(func, events.Handle): |
|
|
|
assert not args |
|
|
|
assert not isinstance(func, events.TimerHandle) |
|
|
|
warnings.warn( |
|
|
|
"Passing Handle to loop.run_in_executor() is deprecated", |
|
|
|
DeprecationWarning) |
|
|
|
if func._cancelled: |
|
|
|
f = self.create_future() |
|
|
|
f.set_result(None) |
|
|
|
return f |
|
|
|
func, args = func._callback, func._args |
|
|
|
if self._debug: |
|
|
|
self._check_callback(func, 'run_in_executor') |
|
|
|
if executor is None: |
|
|
|
executor = self._default_executor |
|
|
|
if executor is None: |
|
|
|
|