blob: bddd7e3649c3d2c5a168d59c180ed98a5bdca761 [file] [log] [blame]
Guido van Rossum27b7c7e2013-10-17 13:40:50 -07001"""Event loop and event loop policy."""
2
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -08003__all__ = ['AbstractEventLoopPolicy',
Guido van Rossum27b7c7e2013-10-17 13:40:50 -07004 'AbstractEventLoop', 'AbstractServer',
5 'Handle', 'TimerHandle',
6 'get_event_loop_policy', 'set_event_loop_policy',
7 'get_event_loop', 'set_event_loop', 'new_event_loop',
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -08008 'get_child_watcher', 'set_child_watcher',
Guido van Rossum27b7c7e2013-10-17 13:40:50 -07009 ]
10
Victor Stinner307bccc2014-06-12 18:39:26 +020011import functools
12import inspect
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070013import subprocess
Victor Stinner80f53aa2014-06-27 13:52:20 +020014import traceback
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070015import threading
16import socket
Victor Stinner307bccc2014-06-12 18:39:26 +020017import sys
18
19
20_PY34 = sys.version_info >= (3, 4)
21
Victor Stinner975735f2014-06-25 21:41:58 +020022
Victor Stinner307bccc2014-06-12 18:39:26 +020023def _get_function_source(func):
24 if _PY34:
25 func = inspect.unwrap(func)
26 elif hasattr(func, '__wrapped__'):
27 func = func.__wrapped__
28 if inspect.isfunction(func):
29 code = func.__code__
30 return (code.co_filename, code.co_firstlineno)
31 if isinstance(func, functools.partial):
32 return _get_function_source(func.func)
33 if _PY34 and isinstance(func, functools.partialmethod):
34 return _get_function_source(func.func)
35 return None
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070036
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070037
Victor Stinner975735f2014-06-25 21:41:58 +020038def _format_args(args):
39 # function formatting ('hello',) as ('hello')
40 args_repr = repr(args)
41 if len(args) == 1 and args_repr.endswith(',)'):
42 args_repr = args_repr[:-2] + ')'
43 return args_repr
44
45
46def _format_callback(func, args, suffix=''):
47 if isinstance(func, functools.partial):
48 if args is not None:
49 suffix = _format_args(args) + suffix
50 return _format_callback(func.func, func.args, suffix)
51
52 func_repr = getattr(func, '__qualname__', None)
53 if not func_repr:
54 func_repr = repr(func)
55
56 if args is not None:
57 func_repr += _format_args(args)
58 if suffix:
59 func_repr += suffix
60
61 source = _get_function_source(func)
62 if source:
63 func_repr += ' at %s:%s' % source
64 return func_repr
65
66
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070067class Handle:
68 """Object returned by callback registration methods."""
69
Victor Stinner80f53aa2014-06-27 13:52:20 +020070 __slots__ = ('_callback', '_args', '_cancelled', '_loop',
71 '_source_traceback', '__weakref__')
Yury Selivanovb1317782014-02-12 17:01:52 -050072
Yury Selivanov569efa22014-02-18 18:02:19 -050073 def __init__(self, callback, args, loop):
Victor Stinnerdc62b7e2014-02-10 00:45:44 +010074 assert not isinstance(callback, Handle), 'A Handle is not a callback'
Yury Selivanov569efa22014-02-18 18:02:19 -050075 self._loop = loop
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070076 self._callback = callback
77 self._args = args
78 self._cancelled = False
Victor Stinner80f53aa2014-06-27 13:52:20 +020079 if self._loop.get_debug():
80 self._source_traceback = traceback.extract_stack(sys._getframe(1))
81 else:
82 self._source_traceback = None
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070083
84 def __repr__(self):
Victor Stinnerf68bd882014-07-10 22:32:58 +020085 info = [self.__class__.__name__]
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070086 if self._cancelled:
Victor Stinner975735f2014-06-25 21:41:58 +020087 info.append('cancelled')
Victor Stinnerf68bd882014-07-10 22:32:58 +020088 if self._callback is not None:
89 info.append(_format_callback(self._callback, self._args))
90 if self._source_traceback:
91 frame = self._source_traceback[-1]
92 info.append('created at %s:%s' % (frame[0], frame[1]))
93 return '<%s>' % ' '.join(info)
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070094
95 def cancel(self):
96 self._cancelled = True
Victor Stinnerf68bd882014-07-10 22:32:58 +020097 self._callback = None
98 self._args = None
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070099
100 def _run(self):
101 try:
102 self._callback(*self._args)
Yury Selivanov569efa22014-02-18 18:02:19 -0500103 except Exception as exc:
Victor Stinner17b53f12014-06-26 01:35:45 +0200104 cb = _format_callback(self._callback, self._args)
105 msg = 'Exception in callback {}'.format(cb)
Victor Stinner80f53aa2014-06-27 13:52:20 +0200106 context = {
Yury Selivanov569efa22014-02-18 18:02:19 -0500107 'message': msg,
108 'exception': exc,
109 'handle': self,
Victor Stinner80f53aa2014-06-27 13:52:20 +0200110 }
111 if self._source_traceback:
112 context['source_traceback'] = self._source_traceback
113 self._loop.call_exception_handler(context)
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700114 self = None # Needed to break cycles when an exception occurs.
115
116
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700117class TimerHandle(Handle):
118 """Object returned by timed callback registration methods."""
119
Yury Selivanovb1317782014-02-12 17:01:52 -0500120 __slots__ = ['_when']
121
Yury Selivanov569efa22014-02-18 18:02:19 -0500122 def __init__(self, when, callback, args, loop):
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700123 assert when is not None
Yury Selivanov569efa22014-02-18 18:02:19 -0500124 super().__init__(callback, args, loop)
Victor Stinner80f53aa2014-06-27 13:52:20 +0200125 if self._source_traceback:
126 del self._source_traceback[-1]
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700127 self._when = when
128
129 def __repr__(self):
Victor Stinner975735f2014-06-25 21:41:58 +0200130 info = []
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700131 if self._cancelled:
Victor Stinner975735f2014-06-25 21:41:58 +0200132 info.append('cancelled')
133 info.append('when=%s' % self._when)
Victor Stinnerf68bd882014-07-10 22:32:58 +0200134 if self._callback is not None:
135 info.append(_format_callback(self._callback, self._args))
136 if self._source_traceback:
137 frame = self._source_traceback[-1]
138 info.append('created at %s:%s' % (frame[0], frame[1]))
Victor Stinner975735f2014-06-25 21:41:58 +0200139 return '<%s %s>' % (self.__class__.__name__, ' '.join(info))
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700140
141 def __hash__(self):
142 return hash(self._when)
143
144 def __lt__(self, other):
145 return self._when < other._when
146
147 def __le__(self, other):
148 if self._when < other._when:
149 return True
150 return self.__eq__(other)
151
152 def __gt__(self, other):
153 return self._when > other._when
154
155 def __ge__(self, other):
156 if self._when > other._when:
157 return True
158 return self.__eq__(other)
159
160 def __eq__(self, other):
161 if isinstance(other, TimerHandle):
162 return (self._when == other._when and
163 self._callback == other._callback and
164 self._args == other._args and
165 self._cancelled == other._cancelled)
166 return NotImplemented
167
168 def __ne__(self, other):
169 equal = self.__eq__(other)
170 return NotImplemented if equal is NotImplemented else not equal
171
172
173class AbstractServer:
Victor Stinnercf6f72e2013-12-03 18:23:52 +0100174 """Abstract server returned by create_server()."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700175
176 def close(self):
177 """Stop serving. This leaves existing connections open."""
178 return NotImplemented
179
180 def wait_closed(self):
181 """Coroutine to wait until service is closed."""
182 return NotImplemented
183
184
185class AbstractEventLoop:
186 """Abstract event loop."""
187
188 # Running and stopping the event loop.
189
190 def run_forever(self):
191 """Run the event loop until stop() is called."""
192 raise NotImplementedError
193
194 def run_until_complete(self, future):
195 """Run the event loop until a Future is done.
196
197 Return the Future's result, or raise its exception.
198 """
199 raise NotImplementedError
200
201 def stop(self):
202 """Stop the event loop as soon as reasonable.
203
204 Exactly how soon that is may depend on the implementation, but
205 no more I/O callbacks should be scheduled.
206 """
207 raise NotImplementedError
208
209 def is_running(self):
210 """Return whether the event loop is currently running."""
211 raise NotImplementedError
212
Victor Stinner896a25a2014-07-08 11:29:25 +0200213 def is_closed(self):
214 """Returns True if the event loop was closed."""
215 raise NotImplementedError
216
Guido van Rossume3f52ef2013-11-01 14:19:04 -0700217 def close(self):
218 """Close the loop.
219
220 The loop should not be running.
221
222 This is idempotent and irreversible.
223
224 No other methods should be called after this one.
225 """
226 raise NotImplementedError
227
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700228 # Methods scheduling callbacks. All these return Handles.
229
230 def call_soon(self, callback, *args):
231 return self.call_later(0, callback, *args)
232
233 def call_later(self, delay, callback, *args):
234 raise NotImplementedError
235
236 def call_at(self, when, callback, *args):
237 raise NotImplementedError
238
239 def time(self):
240 raise NotImplementedError
241
Victor Stinner896a25a2014-07-08 11:29:25 +0200242 # Method scheduling a coroutine object: create a task.
243
244 def create_task(self, coro):
245 raise NotImplementedError
246
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700247 # Methods for interacting with threads.
248
249 def call_soon_threadsafe(self, callback, *args):
250 raise NotImplementedError
251
252 def run_in_executor(self, executor, callback, *args):
253 raise NotImplementedError
254
255 def set_default_executor(self, executor):
256 raise NotImplementedError
257
258 # Network I/O methods returning Futures.
259
260 def getaddrinfo(self, host, port, *, family=0, type=0, proto=0, flags=0):
261 raise NotImplementedError
262
263 def getnameinfo(self, sockaddr, flags=0):
264 raise NotImplementedError
265
266 def create_connection(self, protocol_factory, host=None, port=None, *,
267 ssl=None, family=0, proto=0, flags=0, sock=None,
Guido van Rossum21c85a72013-11-01 14:16:54 -0700268 local_addr=None, server_hostname=None):
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700269 raise NotImplementedError
270
271 def create_server(self, protocol_factory, host=None, port=None, *,
272 family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE,
273 sock=None, backlog=100, ssl=None, reuse_address=None):
274 """A coroutine which creates a TCP server bound to host and port.
275
276 The return value is a Server object which can be used to stop
277 the service.
278
279 If host is an empty string or None all interfaces are assumed
280 and a list of multiple sockets will be returned (most likely
281 one for IPv4 and another one for IPv6).
282
283 family can be set to either AF_INET or AF_INET6 to force the
284 socket to use IPv4 or IPv6. If not set it will be determined
285 from host (defaults to AF_UNSPEC).
286
287 flags is a bitmask for getaddrinfo().
288
289 sock can optionally be specified in order to use a preexisting
290 socket object.
291
292 backlog is the maximum number of queued connections passed to
293 listen() (defaults to 100).
294
295 ssl can be set to an SSLContext to enable SSL over the
296 accepted connections.
297
298 reuse_address tells the kernel to reuse a local socket in
299 TIME_WAIT state, without waiting for its natural timeout to
300 expire. If not specified will automatically be set to True on
301 UNIX.
302 """
303 raise NotImplementedError
304
Yury Selivanovb057c522014-02-18 12:15:06 -0500305 def create_unix_connection(self, protocol_factory, path, *,
306 ssl=None, sock=None,
307 server_hostname=None):
308 raise NotImplementedError
309
310 def create_unix_server(self, protocol_factory, path, *,
311 sock=None, backlog=100, ssl=None):
312 """A coroutine which creates a UNIX Domain Socket server.
313
Yury Selivanovdec1a452014-02-18 22:27:48 -0500314 The return value is a Server object, which can be used to stop
Yury Selivanovb057c522014-02-18 12:15:06 -0500315 the service.
316
317 path is a str, representing a file systsem path to bind the
318 server socket to.
319
320 sock can optionally be specified in order to use a preexisting
321 socket object.
322
323 backlog is the maximum number of queued connections passed to
324 listen() (defaults to 100).
325
326 ssl can be set to an SSLContext to enable SSL over the
327 accepted connections.
328 """
329 raise NotImplementedError
330
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700331 def create_datagram_endpoint(self, protocol_factory,
332 local_addr=None, remote_addr=None, *,
333 family=0, proto=0, flags=0):
334 raise NotImplementedError
335
Guido van Rossume3f52ef2013-11-01 14:19:04 -0700336 # Pipes and subprocesses.
337
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700338 def connect_read_pipe(self, protocol_factory, pipe):
Victor Stinnera5b257a2014-05-29 00:14:03 +0200339 """Register read pipe in event loop. Set the pipe to non-blocking mode.
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700340
341 protocol_factory should instantiate object with Protocol interface.
Victor Stinnera5b257a2014-05-29 00:14:03 +0200342 pipe is a file-like object.
343 Return pair (transport, protocol), where transport supports the
Guido van Rossum9204af42013-11-30 15:35:42 -0800344 ReadTransport interface."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700345 # The reason to accept file-like object instead of just file descriptor
346 # is: we need to own pipe and close it at transport finishing
347 # Can got complicated errors if pass f.fileno(),
348 # close fd in pipe transport then close f and vise versa.
349 raise NotImplementedError
350
351 def connect_write_pipe(self, protocol_factory, pipe):
Yury Selivanovdec1a452014-02-18 22:27:48 -0500352 """Register write pipe in event loop.
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700353
354 protocol_factory should instantiate object with BaseProtocol interface.
355 Pipe is file-like object already switched to nonblocking.
356 Return pair (transport, protocol), where transport support
Guido van Rossum9204af42013-11-30 15:35:42 -0800357 WriteTransport interface."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700358 # The reason to accept file-like object instead of just file descriptor
359 # is: we need to own pipe and close it at transport finishing
360 # Can got complicated errors if pass f.fileno(),
361 # close fd in pipe transport then close f and vise versa.
362 raise NotImplementedError
363
364 def subprocess_shell(self, protocol_factory, cmd, *, stdin=subprocess.PIPE,
365 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
366 **kwargs):
367 raise NotImplementedError
368
369 def subprocess_exec(self, protocol_factory, *args, stdin=subprocess.PIPE,
370 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
371 **kwargs):
372 raise NotImplementedError
373
374 # Ready-based callback registration methods.
375 # The add_*() methods return None.
376 # The remove_*() methods return True if something was removed,
377 # False if there was nothing to delete.
378
379 def add_reader(self, fd, callback, *args):
380 raise NotImplementedError
381
382 def remove_reader(self, fd):
383 raise NotImplementedError
384
385 def add_writer(self, fd, callback, *args):
386 raise NotImplementedError
387
388 def remove_writer(self, fd):
389 raise NotImplementedError
390
391 # Completion based I/O methods returning Futures.
392
393 def sock_recv(self, sock, nbytes):
394 raise NotImplementedError
395
396 def sock_sendall(self, sock, data):
397 raise NotImplementedError
398
399 def sock_connect(self, sock, address):
400 raise NotImplementedError
401
402 def sock_accept(self, sock):
403 raise NotImplementedError
404
405 # Signal handling.
406
407 def add_signal_handler(self, sig, callback, *args):
408 raise NotImplementedError
409
410 def remove_signal_handler(self, sig):
411 raise NotImplementedError
412
Yury Selivanov569efa22014-02-18 18:02:19 -0500413 # Error handlers.
414
415 def set_exception_handler(self, handler):
416 raise NotImplementedError
417
418 def default_exception_handler(self, context):
419 raise NotImplementedError
420
421 def call_exception_handler(self, context):
422 raise NotImplementedError
423
Victor Stinner0f3e6bc2014-02-19 23:15:02 +0100424 # Debug flag management.
425
426 def get_debug(self):
427 raise NotImplementedError
428
429 def set_debug(self, enabled):
430 raise NotImplementedError
431
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700432
433class AbstractEventLoopPolicy:
434 """Abstract policy for accessing the event loop."""
435
436 def get_event_loop(self):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200437 """Get the event loop for the current context.
438
439 Returns an event loop object implementing the BaseEventLoop interface,
440 or raises an exception in case no event loop has been set for the
441 current context and the current policy does not specify to create one.
442
443 It should never return None."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700444 raise NotImplementedError
445
446 def set_event_loop(self, loop):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200447 """Set the event loop for the current context to loop."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700448 raise NotImplementedError
449
450 def new_event_loop(self):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200451 """Create and return a new event loop object according to this
452 policy's rules. If there's need to set this loop as the event loop for
453 the current context, set_event_loop must be called explicitly."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700454 raise NotImplementedError
455
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800456 # Child processes handling (Unix only).
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700457
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800458 def get_child_watcher(self):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200459 "Get the watcher for child processes."
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800460 raise NotImplementedError
461
462 def set_child_watcher(self, watcher):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200463 """Set the watcher for child processes."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800464 raise NotImplementedError
465
466
467class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700468 """Default policy implementation for accessing the event loop.
469
470 In this policy, each thread has its own event loop. However, we
471 only automatically create an event loop by default for the main
472 thread; other threads by default have no event loop.
473
474 Other policies may have different rules (e.g. a single global
475 event loop, or automatically creating an event loop per thread, or
476 using some other notion of context to which an event loop is
477 associated).
478 """
479
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800480 _loop_factory = None
481
482 class _Local(threading.local):
483 _loop = None
484 _set_called = False
485
486 def __init__(self):
487 self._local = self._Local()
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700488
489 def get_event_loop(self):
490 """Get the event loop.
491
492 This may be None or an instance of EventLoop.
493 """
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800494 if (self._local._loop is None and
495 not self._local._set_called and
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700496 isinstance(threading.current_thread(), threading._MainThread)):
Guido van Rossumcced0762013-11-27 10:37:13 -0800497 self.set_event_loop(self.new_event_loop())
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800498 assert self._local._loop is not None, \
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700499 ('There is no current event loop in thread %r.' %
500 threading.current_thread().name)
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800501 return self._local._loop
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700502
503 def set_event_loop(self, loop):
504 """Set the event loop."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800505 self._local._set_called = True
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700506 assert loop is None or isinstance(loop, AbstractEventLoop)
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800507 self._local._loop = loop
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700508
509 def new_event_loop(self):
510 """Create a new event loop.
511
512 You must call set_event_loop() to make this the current event
513 loop.
514 """
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800515 return self._loop_factory()
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700516
517
518# Event loop policy. The policy itself is always global, even if the
519# policy's rules say that there is an event loop per thread (or other
520# notion of context). The default policy is installed by the first
521# call to get_event_loop_policy().
522_event_loop_policy = None
523
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800524# Lock for protecting the on-the-fly creation of the event loop policy.
525_lock = threading.Lock()
526
527
528def _init_event_loop_policy():
529 global _event_loop_policy
530 with _lock:
531 if _event_loop_policy is None: # pragma: no branch
532 from . import DefaultEventLoopPolicy
533 _event_loop_policy = DefaultEventLoopPolicy()
534
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700535
536def get_event_loop_policy():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200537 """Get the current event loop policy."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700538 if _event_loop_policy is None:
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800539 _init_event_loop_policy()
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700540 return _event_loop_policy
541
542
543def set_event_loop_policy(policy):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200544 """Set the current event loop policy.
545
546 If policy is None, the default policy is restored."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700547 global _event_loop_policy
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700548 assert policy is None or isinstance(policy, AbstractEventLoopPolicy)
549 _event_loop_policy = policy
550
551
552def get_event_loop():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200553 """Equivalent to calling get_event_loop_policy().get_event_loop()."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700554 return get_event_loop_policy().get_event_loop()
555
556
557def set_event_loop(loop):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200558 """Equivalent to calling get_event_loop_policy().set_event_loop(loop)."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700559 get_event_loop_policy().set_event_loop(loop)
560
561
562def new_event_loop():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200563 """Equivalent to calling get_event_loop_policy().new_event_loop()."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700564 return get_event_loop_policy().new_event_loop()
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800565
566
567def get_child_watcher():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200568 """Equivalent to calling get_event_loop_policy().get_child_watcher()."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800569 return get_event_loop_policy().get_child_watcher()
570
571
572def set_child_watcher(watcher):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200573 """Equivalent to calling
574 get_event_loop_policy().set_child_watcher(watcher)."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800575 return get_event_loop_policy().set_child_watcher(watcher)