Exemple #1
0
    def get_event_loop(self):
        """
		Get the event loop for the current context.

		Returns an event loop object implementing the AbstractEventLoop
		interface.

		@rtype: asyncio.AbstractEventLoop (or compatible)
		@return: the current event loop policy
		"""
        return _global_event_loop()._asyncio_wrapper
Exemple #2
0
	def get_event_loop(self):
		"""
		Get the event loop for the current context.

		Returns an event loop object implementing the AbstractEventLoop
		interface.

		@rtype: asyncio.AbstractEventLoop (or compatible)
		@return: the current event loop policy
		"""
		return _global_event_loop()._asyncio_wrapper
Exemple #3
0
def _safe_loop():
    """
	Return an event loop that's safe to use within the current context.
	For portage internal callers, this returns a globally shared event
	loop instance. For external API consumers, this constructs a
	temporary event loop instance that's safe to use in a non-main
	thread (it does not override the global SIGCHLD handler).

	@rtype: asyncio.AbstractEventLoop (or compatible)
	@return: event loop instance
	"""
    if portage._internal_caller:
        return _global_event_loop()
    return _EventLoop(main=False)
Exemple #4
0
def _safe_loop():
	"""
	Return an event loop that's safe to use within the current context.
	For portage internal callers, this returns a globally shared event
	loop instance. For external API consumers, this constructs a
	temporary event loop instance that's safe to use in a non-main
	thread (it does not override the global SIGCHLD handler).

	@rtype: asyncio.AbstractEventLoop (or compatible)
	@return: event loop instance
	"""
	if portage._internal_caller:
		return _global_event_loop()
	else:
		return _EventLoop(main=False)
Exemple #5
0
def _wrap_loop(loop=None):
	"""
	In order to deal with asyncio event loop compatibility issues,
	use this function to wrap the loop parameter for functions
	that support it. For example, since python3.4 does not have the
	AbstractEventLoop.create_future() method, this helper function
	can be used to add a wrapper that implements the create_future
	method for python3.4.

	@type loop: asyncio.AbstractEventLoop (or compatible)
	@param loop: event loop
	@rtype: asyncio.AbstractEventLoop (or compatible)
	@return: event loop
	"""
	return loop or _global_event_loop()
Exemple #6
0
def _wrap_loop(loop=None):
	"""
	In order to deal with asyncio event loop compatibility issues,
	use this function to wrap the loop parameter for functions
	that support it. For example, since python3.4 does not have the
	AbstractEventLoop.create_future() method, this helper function
	can be used to add a wrapper that implements the create_future
	method for python3.4.

	@type loop: asyncio.AbstractEventLoop (or compatible)
	@param loop: event loop
	@rtype: asyncio.AbstractEventLoop (or compatible)
	@return: event loop
	"""
	# The default loop returned by _wrap_loop should be consistent
	# with global_event_loop, in order to avoid accidental registration
	# of callbacks with a loop that is not intended to run.
	loop = loop or _global_event_loop()
	return (loop if hasattr(loop, '_asyncio_wrapper')
		else _AsyncioEventLoop(loop=loop))
Exemple #7
0
def wait(futures, loop=None, timeout=None, return_when=ALL_COMPLETED):
	"""
	Use portage's internal EventLoop to emulate asyncio.wait:
	https://docs.python.org/3/library/asyncio-task.html#asyncio.wait

	@param futures: futures to wait for
	@type futures: asyncio.Future (or compatible)
	@param timeout: number of seconds to wait (wait indefinitely if
		not specified)
	@type timeout: int or float
	@param return_when: indicates when this function should return, must
		be one of the constants ALL_COMPLETED, FIRST_COMPLETED, or
		FIRST_EXCEPTION (default is ALL_COMPLETED)
	@type return_when: object
	@param loop: event loop
	@type loop: EventLoop
	@return: tuple of (done, pending).
	@rtype: asyncio.Future (or compatible)
	"""
	loop = loop or _global_event_loop()
	loop = getattr(loop, '_asyncio_wrapper', loop)
	result_future = loop.create_future()
	_Waiter(futures, timeout, return_when, result_future, loop)
	return result_future
Exemple #8
0
	def _wrap_loop(loop=None):
		loop = loop or _global_event_loop()
		return (loop if hasattr(loop, '_asyncio_wrapper')
			else _AsyncioEventLoop(loop=loop))
Exemple #9
0
 def get_child_watcher(self):
     """Get the watcher for child processes."""
     return _global_event_loop()._asyncio_child_watcher
Exemple #10
0
	def get_child_watcher(self):
		"""Get the watcher for child processes."""
		return _global_event_loop()._asyncio_child_watcher