blob: 3c7a36d0763ffeb7f2d22ce93e0b1d6811b0dbdf [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
Victor Stinner313a9802014-07-29 12:58:23 +020013import reprlib
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070014import socket
Victor Stinner313a9802014-07-29 12:58:23 +020015import subprocess
Victor Stinner307bccc2014-06-12 18:39:26 +020016import sys
Victor Stinner313a9802014-07-29 12:58:23 +020017import threading
18import traceback
Victor Stinner307bccc2014-06-12 18:39:26 +020019
20
21_PY34 = sys.version_info >= (3, 4)
22
Victor Stinner975735f2014-06-25 21:41:58 +020023
Victor Stinner307bccc2014-06-12 18:39:26 +020024def _get_function_source(func):
25 if _PY34:
26 func = inspect.unwrap(func)
27 elif hasattr(func, '__wrapped__'):
28 func = func.__wrapped__
29 if inspect.isfunction(func):
30 code = func.__code__
31 return (code.co_filename, code.co_firstlineno)
32 if isinstance(func, functools.partial):
33 return _get_function_source(func.func)
34 if _PY34 and isinstance(func, functools.partialmethod):
35 return _get_function_source(func.func)
36 return None
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070037
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070038
Victor Stinner975735f2014-06-25 21:41:58 +020039def _format_args(args):
Victor Stinner313a9802014-07-29 12:58:23 +020040 """Format function arguments.
41
42 Special case for a single parameter: ('hello',) is formatted as ('hello').
43 """
44 # use reprlib to limit the length of the output
45 args_repr = reprlib.repr(args)
Victor Stinner975735f2014-06-25 21:41:58 +020046 if len(args) == 1 and args_repr.endswith(',)'):
47 args_repr = args_repr[:-2] + ')'
48 return args_repr
49
50
51def _format_callback(func, args, suffix=''):
52 if isinstance(func, functools.partial):
53 if args is not None:
54 suffix = _format_args(args) + suffix
55 return _format_callback(func.func, func.args, suffix)
56
57 func_repr = getattr(func, '__qualname__', None)
58 if not func_repr:
59 func_repr = repr(func)
60
61 if args is not None:
62 func_repr += _format_args(args)
63 if suffix:
64 func_repr += suffix
65
66 source = _get_function_source(func)
67 if source:
68 func_repr += ' at %s:%s' % source
69 return func_repr
70
71
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070072class Handle:
73 """Object returned by callback registration methods."""
74
Victor Stinner80f53aa2014-06-27 13:52:20 +020075 __slots__ = ('_callback', '_args', '_cancelled', '_loop',
76 '_source_traceback', '__weakref__')
Yury Selivanovb1317782014-02-12 17:01:52 -050077
Yury Selivanov569efa22014-02-18 18:02:19 -050078 def __init__(self, callback, args, loop):
Victor Stinnerdc62b7e2014-02-10 00:45:44 +010079 assert not isinstance(callback, Handle), 'A Handle is not a callback'
Yury Selivanov569efa22014-02-18 18:02:19 -050080 self._loop = loop
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070081 self._callback = callback
82 self._args = args
83 self._cancelled = False
Victor Stinner80f53aa2014-06-27 13:52:20 +020084 if self._loop.get_debug():
85 self._source_traceback = traceback.extract_stack(sys._getframe(1))
86 else:
87 self._source_traceback = None
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070088
89 def __repr__(self):
Victor Stinnerf68bd882014-07-10 22:32:58 +020090 info = [self.__class__.__name__]
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070091 if self._cancelled:
Victor Stinner975735f2014-06-25 21:41:58 +020092 info.append('cancelled')
Victor Stinnerf68bd882014-07-10 22:32:58 +020093 if self._callback is not None:
94 info.append(_format_callback(self._callback, self._args))
95 if self._source_traceback:
96 frame = self._source_traceback[-1]
97 info.append('created at %s:%s' % (frame[0], frame[1]))
98 return '<%s>' % ' '.join(info)
Guido van Rossum27b7c7e2013-10-17 13:40:50 -070099
100 def cancel(self):
101 self._cancelled = True
Victor Stinnerf68bd882014-07-10 22:32:58 +0200102 self._callback = None
103 self._args = None
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700104
105 def _run(self):
106 try:
107 self._callback(*self._args)
Yury Selivanov569efa22014-02-18 18:02:19 -0500108 except Exception as exc:
Victor Stinner17b53f12014-06-26 01:35:45 +0200109 cb = _format_callback(self._callback, self._args)
110 msg = 'Exception in callback {}'.format(cb)
Victor Stinner80f53aa2014-06-27 13:52:20 +0200111 context = {
Yury Selivanov569efa22014-02-18 18:02:19 -0500112 'message': msg,
113 'exception': exc,
114 'handle': self,
Victor Stinner80f53aa2014-06-27 13:52:20 +0200115 }
116 if self._source_traceback:
117 context['source_traceback'] = self._source_traceback
118 self._loop.call_exception_handler(context)
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700119 self = None # Needed to break cycles when an exception occurs.
120
121
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700122class TimerHandle(Handle):
123 """Object returned by timed callback registration methods."""
124
Yury Selivanovb1317782014-02-12 17:01:52 -0500125 __slots__ = ['_when']
126
Yury Selivanov569efa22014-02-18 18:02:19 -0500127 def __init__(self, when, callback, args, loop):
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700128 assert when is not None
Yury Selivanov569efa22014-02-18 18:02:19 -0500129 super().__init__(callback, args, loop)
Victor Stinner80f53aa2014-06-27 13:52:20 +0200130 if self._source_traceback:
131 del self._source_traceback[-1]
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700132 self._when = when
133
134 def __repr__(self):
Victor Stinner975735f2014-06-25 21:41:58 +0200135 info = []
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700136 if self._cancelled:
Victor Stinner975735f2014-06-25 21:41:58 +0200137 info.append('cancelled')
138 info.append('when=%s' % self._when)
Victor Stinnerf68bd882014-07-10 22:32:58 +0200139 if self._callback is not None:
140 info.append(_format_callback(self._callback, self._args))
141 if self._source_traceback:
142 frame = self._source_traceback[-1]
143 info.append('created at %s:%s' % (frame[0], frame[1]))
Victor Stinner975735f2014-06-25 21:41:58 +0200144 return '<%s %s>' % (self.__class__.__name__, ' '.join(info))
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700145
146 def __hash__(self):
147 return hash(self._when)
148
149 def __lt__(self, other):
150 return self._when < other._when
151
152 def __le__(self, other):
153 if self._when < other._when:
154 return True
155 return self.__eq__(other)
156
157 def __gt__(self, other):
158 return self._when > other._when
159
160 def __ge__(self, other):
161 if self._when > other._when:
162 return True
163 return self.__eq__(other)
164
165 def __eq__(self, other):
166 if isinstance(other, TimerHandle):
167 return (self._when == other._when and
168 self._callback == other._callback and
169 self._args == other._args and
170 self._cancelled == other._cancelled)
171 return NotImplemented
172
173 def __ne__(self, other):
174 equal = self.__eq__(other)
175 return NotImplemented if equal is NotImplemented else not equal
176
177
178class AbstractServer:
Victor Stinnercf6f72e2013-12-03 18:23:52 +0100179 """Abstract server returned by create_server()."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700180
181 def close(self):
182 """Stop serving. This leaves existing connections open."""
183 return NotImplemented
184
185 def wait_closed(self):
186 """Coroutine to wait until service is closed."""
187 return NotImplemented
188
189
190class AbstractEventLoop:
191 """Abstract event loop."""
192
193 # Running and stopping the event loop.
194
195 def run_forever(self):
196 """Run the event loop until stop() is called."""
197 raise NotImplementedError
198
199 def run_until_complete(self, future):
200 """Run the event loop until a Future is done.
201
202 Return the Future's result, or raise its exception.
203 """
204 raise NotImplementedError
205
206 def stop(self):
207 """Stop the event loop as soon as reasonable.
208
209 Exactly how soon that is may depend on the implementation, but
210 no more I/O callbacks should be scheduled.
211 """
212 raise NotImplementedError
213
214 def is_running(self):
215 """Return whether the event loop is currently running."""
216 raise NotImplementedError
217
Victor Stinner896a25a2014-07-08 11:29:25 +0200218 def is_closed(self):
219 """Returns True if the event loop was closed."""
220 raise NotImplementedError
221
Guido van Rossume3f52ef2013-11-01 14:19:04 -0700222 def close(self):
223 """Close the loop.
224
225 The loop should not be running.
226
227 This is idempotent and irreversible.
228
229 No other methods should be called after this one.
230 """
231 raise NotImplementedError
232
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700233 # Methods scheduling callbacks. All these return Handles.
234
235 def call_soon(self, callback, *args):
236 return self.call_later(0, callback, *args)
237
238 def call_later(self, delay, callback, *args):
239 raise NotImplementedError
240
241 def call_at(self, when, callback, *args):
242 raise NotImplementedError
243
244 def time(self):
245 raise NotImplementedError
246
Victor Stinner896a25a2014-07-08 11:29:25 +0200247 # Method scheduling a coroutine object: create a task.
248
249 def create_task(self, coro):
250 raise NotImplementedError
251
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700252 # Methods for interacting with threads.
253
254 def call_soon_threadsafe(self, callback, *args):
255 raise NotImplementedError
256
257 def run_in_executor(self, executor, callback, *args):
258 raise NotImplementedError
259
260 def set_default_executor(self, executor):
261 raise NotImplementedError
262
263 # Network I/O methods returning Futures.
264
265 def getaddrinfo(self, host, port, *, family=0, type=0, proto=0, flags=0):
266 raise NotImplementedError
267
268 def getnameinfo(self, sockaddr, flags=0):
269 raise NotImplementedError
270
271 def create_connection(self, protocol_factory, host=None, port=None, *,
272 ssl=None, family=0, proto=0, flags=0, sock=None,
Guido van Rossum21c85a72013-11-01 14:16:54 -0700273 local_addr=None, server_hostname=None):
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700274 raise NotImplementedError
275
276 def create_server(self, protocol_factory, host=None, port=None, *,
277 family=socket.AF_UNSPEC, flags=socket.AI_PASSIVE,
278 sock=None, backlog=100, ssl=None, reuse_address=None):
279 """A coroutine which creates a TCP server bound to host and port.
280
281 The return value is a Server object which can be used to stop
282 the service.
283
284 If host is an empty string or None all interfaces are assumed
285 and a list of multiple sockets will be returned (most likely
286 one for IPv4 and another one for IPv6).
287
288 family can be set to either AF_INET or AF_INET6 to force the
289 socket to use IPv4 or IPv6. If not set it will be determined
290 from host (defaults to AF_UNSPEC).
291
292 flags is a bitmask for getaddrinfo().
293
294 sock can optionally be specified in order to use a preexisting
295 socket object.
296
297 backlog is the maximum number of queued connections passed to
298 listen() (defaults to 100).
299
300 ssl can be set to an SSLContext to enable SSL over the
301 accepted connections.
302
303 reuse_address tells the kernel to reuse a local socket in
304 TIME_WAIT state, without waiting for its natural timeout to
305 expire. If not specified will automatically be set to True on
306 UNIX.
307 """
308 raise NotImplementedError
309
Yury Selivanovb057c522014-02-18 12:15:06 -0500310 def create_unix_connection(self, protocol_factory, path, *,
311 ssl=None, sock=None,
312 server_hostname=None):
313 raise NotImplementedError
314
315 def create_unix_server(self, protocol_factory, path, *,
316 sock=None, backlog=100, ssl=None):
317 """A coroutine which creates a UNIX Domain Socket server.
318
Yury Selivanovdec1a452014-02-18 22:27:48 -0500319 The return value is a Server object, which can be used to stop
Yury Selivanovb057c522014-02-18 12:15:06 -0500320 the service.
321
322 path is a str, representing a file systsem path to bind the
323 server socket to.
324
325 sock can optionally be specified in order to use a preexisting
326 socket object.
327
328 backlog is the maximum number of queued connections passed to
329 listen() (defaults to 100).
330
331 ssl can be set to an SSLContext to enable SSL over the
332 accepted connections.
333 """
334 raise NotImplementedError
335
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700336 def create_datagram_endpoint(self, protocol_factory,
337 local_addr=None, remote_addr=None, *,
338 family=0, proto=0, flags=0):
339 raise NotImplementedError
340
Guido van Rossume3f52ef2013-11-01 14:19:04 -0700341 # Pipes and subprocesses.
342
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700343 def connect_read_pipe(self, protocol_factory, pipe):
Victor Stinnera5b257a2014-05-29 00:14:03 +0200344 """Register read pipe in event loop. Set the pipe to non-blocking mode.
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700345
346 protocol_factory should instantiate object with Protocol interface.
Victor Stinnera5b257a2014-05-29 00:14:03 +0200347 pipe is a file-like object.
348 Return pair (transport, protocol), where transport supports the
Guido van Rossum9204af42013-11-30 15:35:42 -0800349 ReadTransport interface."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700350 # The reason to accept file-like object instead of just file descriptor
351 # is: we need to own pipe and close it at transport finishing
352 # Can got complicated errors if pass f.fileno(),
353 # close fd in pipe transport then close f and vise versa.
354 raise NotImplementedError
355
356 def connect_write_pipe(self, protocol_factory, pipe):
Yury Selivanovdec1a452014-02-18 22:27:48 -0500357 """Register write pipe in event loop.
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700358
359 protocol_factory should instantiate object with BaseProtocol interface.
360 Pipe is file-like object already switched to nonblocking.
361 Return pair (transport, protocol), where transport support
Guido van Rossum9204af42013-11-30 15:35:42 -0800362 WriteTransport interface."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700363 # The reason to accept file-like object instead of just file descriptor
364 # is: we need to own pipe and close it at transport finishing
365 # Can got complicated errors if pass f.fileno(),
366 # close fd in pipe transport then close f and vise versa.
367 raise NotImplementedError
368
369 def subprocess_shell(self, protocol_factory, cmd, *, stdin=subprocess.PIPE,
370 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
371 **kwargs):
372 raise NotImplementedError
373
374 def subprocess_exec(self, protocol_factory, *args, stdin=subprocess.PIPE,
375 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
376 **kwargs):
377 raise NotImplementedError
378
379 # Ready-based callback registration methods.
380 # The add_*() methods return None.
381 # The remove_*() methods return True if something was removed,
382 # False if there was nothing to delete.
383
384 def add_reader(self, fd, callback, *args):
385 raise NotImplementedError
386
387 def remove_reader(self, fd):
388 raise NotImplementedError
389
390 def add_writer(self, fd, callback, *args):
391 raise NotImplementedError
392
393 def remove_writer(self, fd):
394 raise NotImplementedError
395
396 # Completion based I/O methods returning Futures.
397
398 def sock_recv(self, sock, nbytes):
399 raise NotImplementedError
400
401 def sock_sendall(self, sock, data):
402 raise NotImplementedError
403
404 def sock_connect(self, sock, address):
405 raise NotImplementedError
406
407 def sock_accept(self, sock):
408 raise NotImplementedError
409
410 # Signal handling.
411
412 def add_signal_handler(self, sig, callback, *args):
413 raise NotImplementedError
414
415 def remove_signal_handler(self, sig):
416 raise NotImplementedError
417
Yury Selivanov569efa22014-02-18 18:02:19 -0500418 # Error handlers.
419
420 def set_exception_handler(self, handler):
421 raise NotImplementedError
422
423 def default_exception_handler(self, context):
424 raise NotImplementedError
425
426 def call_exception_handler(self, context):
427 raise NotImplementedError
428
Victor Stinner0f3e6bc2014-02-19 23:15:02 +0100429 # Debug flag management.
430
431 def get_debug(self):
432 raise NotImplementedError
433
434 def set_debug(self, enabled):
435 raise NotImplementedError
436
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700437
438class AbstractEventLoopPolicy:
439 """Abstract policy for accessing the event loop."""
440
441 def get_event_loop(self):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200442 """Get the event loop for the current context.
443
444 Returns an event loop object implementing the BaseEventLoop interface,
445 or raises an exception in case no event loop has been set for the
446 current context and the current policy does not specify to create one.
447
448 It should never return None."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700449 raise NotImplementedError
450
451 def set_event_loop(self, loop):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200452 """Set the event loop for the current context to loop."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700453 raise NotImplementedError
454
455 def new_event_loop(self):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200456 """Create and return a new event loop object according to this
457 policy's rules. If there's need to set this loop as the event loop for
458 the current context, set_event_loop must be called explicitly."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700459 raise NotImplementedError
460
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800461 # Child processes handling (Unix only).
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700462
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800463 def get_child_watcher(self):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200464 "Get the watcher for child processes."
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800465 raise NotImplementedError
466
467 def set_child_watcher(self, watcher):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200468 """Set the watcher for child processes."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800469 raise NotImplementedError
470
471
472class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700473 """Default policy implementation for accessing the event loop.
474
475 In this policy, each thread has its own event loop. However, we
476 only automatically create an event loop by default for the main
477 thread; other threads by default have no event loop.
478
479 Other policies may have different rules (e.g. a single global
480 event loop, or automatically creating an event loop per thread, or
481 using some other notion of context to which an event loop is
482 associated).
483 """
484
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800485 _loop_factory = None
486
487 class _Local(threading.local):
488 _loop = None
489 _set_called = False
490
491 def __init__(self):
492 self._local = self._Local()
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700493
494 def get_event_loop(self):
495 """Get the event loop.
496
497 This may be None or an instance of EventLoop.
498 """
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800499 if (self._local._loop is None and
500 not self._local._set_called and
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700501 isinstance(threading.current_thread(), threading._MainThread)):
Guido van Rossumcced0762013-11-27 10:37:13 -0800502 self.set_event_loop(self.new_event_loop())
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800503 assert self._local._loop is not None, \
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700504 ('There is no current event loop in thread %r.' %
505 threading.current_thread().name)
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800506 return self._local._loop
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700507
508 def set_event_loop(self, loop):
509 """Set the event loop."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800510 self._local._set_called = True
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700511 assert loop is None or isinstance(loop, AbstractEventLoop)
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800512 self._local._loop = loop
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700513
514 def new_event_loop(self):
515 """Create a new event loop.
516
517 You must call set_event_loop() to make this the current event
518 loop.
519 """
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800520 return self._loop_factory()
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700521
522
523# Event loop policy. The policy itself is always global, even if the
524# policy's rules say that there is an event loop per thread (or other
525# notion of context). The default policy is installed by the first
526# call to get_event_loop_policy().
527_event_loop_policy = None
528
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800529# Lock for protecting the on-the-fly creation of the event loop policy.
530_lock = threading.Lock()
531
532
533def _init_event_loop_policy():
534 global _event_loop_policy
535 with _lock:
536 if _event_loop_policy is None: # pragma: no branch
537 from . import DefaultEventLoopPolicy
538 _event_loop_policy = DefaultEventLoopPolicy()
539
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700540
541def get_event_loop_policy():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200542 """Get the current event loop policy."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700543 if _event_loop_policy is None:
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800544 _init_event_loop_policy()
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700545 return _event_loop_policy
546
547
548def set_event_loop_policy(policy):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200549 """Set the current event loop policy.
550
551 If policy is None, the default policy is restored."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700552 global _event_loop_policy
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700553 assert policy is None or isinstance(policy, AbstractEventLoopPolicy)
554 _event_loop_policy = policy
555
556
557def get_event_loop():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200558 """Equivalent to calling get_event_loop_policy().get_event_loop()."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700559 return get_event_loop_policy().get_event_loop()
560
561
562def set_event_loop(loop):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200563 """Equivalent to calling get_event_loop_policy().set_event_loop(loop)."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700564 get_event_loop_policy().set_event_loop(loop)
565
566
567def new_event_loop():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200568 """Equivalent to calling get_event_loop_policy().new_event_loop()."""
Guido van Rossum27b7c7e2013-10-17 13:40:50 -0700569 return get_event_loop_policy().new_event_loop()
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800570
571
572def get_child_watcher():
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200573 """Equivalent to calling get_event_loop_policy().get_child_watcher()."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800574 return get_event_loop_policy().get_child_watcher()
575
576
577def set_child_watcher(watcher):
Victor Stinnerf9e49dd2014-06-05 12:06:44 +0200578 """Equivalent to calling
579 get_event_loop_policy().set_child_watcher(watcher)."""
Guido van Rossum0eaa5ac2013-11-04 15:50:46 -0800580 return get_event_loop_policy().set_child_watcher(watcher)