summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-11-03 22:10:11 (GMT)
committerYury Selivanov <yury@magic.io>2016-11-03 22:10:11 (GMT)
commita6fbcd19ac3e821f53159d06d643de65c70c1050 (patch)
tree28b50212ab2cffb284283decd633106da17809f7 /Lib/asyncio
parent4948a462e82fce85e94e12bf47b7a14aef2dc466 (diff)
parent491a912659a4aeb57c400f37b8059fa1ef7bed73 (diff)
downloadcpython-a6fbcd19ac3e821f53159d06d643de65c70c1050.zip
cpython-a6fbcd19ac3e821f53159d06d643de65c70c1050.tar.gz
cpython-a6fbcd19ac3e821f53159d06d643de65c70c1050.tar.bz2
Merge 3.5 (issue #28600)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py40
-rw-r--r--Lib/asyncio/events.py1
2 files changed, 19 insertions, 22 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index cc9994d..68e676b 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -532,12 +532,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]
@@ -555,18 +553,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]
@@ -592,6 +599,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]
@@ -599,21 +609,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:
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 3a33646..b89b4b2 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -82,7 +82,6 @@ class Handle:
'_source_traceback', '_repr', '__weakref__')
def __init__(self, callback, args, loop):
- assert not isinstance(callback, Handle), 'A Handle is not a callback'
self._loop = loop
self._callback = callback
self._args = args