_emerge.AsynchronousLock module

class _emerge.AsynchronousLock.AsynchronousLock(**kwargs)

Bases: _emerge.AsynchronousTask.AsynchronousTask

This uses the portage.locks module to acquire a lock asynchronously, using either a thread (if available) or a subprocess.

The default behavior is to use a process instead of a thread, since there is currently no way to interrupt a thread that is waiting for a lock (notably, SIGINT doesn’t work because python delivers all signals to the main thread).

_async_wait()

Subclasses call this method in order to invoke exit listeners when self.returncode is set. Subclasses may override this method in order to perform cleanup. The default implementation for this method simply calls self.wait(), which will immediately raise an InvalidStateError if the event loop is running and self.returncode is None.

_cancel()

Subclasses should implement this, as a template method to be called by AsynchronousTask.cancel().

_cancelled_returncode = -2
_exit_listener_cb(listener)
_exit_listener_handles
_exit_listeners
_force_async
_force_dummy
_force_process
_force_thread
_imp
_imp_exit(imp)
_poll()
_start()
_start_hook()
_start_listeners
_unlock_future
_use_process_by_default = True
_wait_hook()

Call this method after the task completes, just before returning the returncode from wait() or poll(). This hook is used to trigger exit listeners when the returncode first becomes available.

_was_cancelled()

If cancelled, set returncode if necessary and return True. Otherwise, return False.

addExitListener(f)

The function will be called with one argument, a reference to self.

addStartListener(f)

The function will be called with one argument, a reference to self.

async_unlock()

Release the lock asynchronously. Release notification is available via the add_done_callback method of the returned Future instance.

Returns

Future, result is None

async_wait()

Wait for returncode asynchronously. Notification is available via the add_done_callback method of the returned Future instance.

Returns

Future, result is self.returncode

background
cancel()

Cancel the task, but do not wait for exit status. If asynchronous exit notification is desired, then use addExitListener to add a listener before calling this method. NOTE: Synchronous waiting for status is not supported, since it would be vulnerable to hitting the recursion limit when a large number of tasks need to be terminated simultaneously, like in bug #402335.

cancelled
copy()

Create a new instance and copy all attributes defined from __slots__ (including those from inherited classes).

isAlive()
path
poll()
removeExitListener(f)
removeStartListener(f)
returncode
scheduler
start()

Start an asynchronous task and then return as soon as possible.

wait()

Wait for the returncode attribute to become ready, and return it. If the returncode is not ready and the event loop is already running, then the async_wait() method should be used instead of wait(), because wait() will raise asyncio.InvalidStateError in this case.

Return type

int

Returns

the value of self.returncode

class _emerge.AsynchronousLock._LockProcess(**kwargs)

Bases: _emerge.AbstractPollTask.AbstractPollTask

This uses the portage.locks module to acquire a lock asynchronously, using a subprocess. After the lock is acquired, the process writes to a pipe in order to notify a poll loop running in the main process. The unlock() method notifies the subprocess to release the lock and exit.

_acquired
_async_wait()

Subclasses call this method in order to invoke exit listeners when self.returncode is set. Subclasses may override this method in order to perform cleanup. The default implementation for this method simply calls self.wait(), which will immediately raise an InvalidStateError if the event loop is running and self.returncode is None.

_bufsize = 4096
_cancel()

Subclasses should implement this, as a template method to be called by AsynchronousTask.cancel().

_cancelled_returncode = -2
_exit_listener_cb(listener)
_exit_listener_handles
_exit_listeners
_files
_kill_test
_output_handler()
_poll()
_proc
_proc_exit(proc)
_read_array(f)

NOTE: array.fromfile() is used here only for testing purposes, because it has bugs in all known versions of Python (including Python 2.7 and Python 3.2). See PipeReaderArrayTestCase.

A benchmark that copies bytes from /dev/zero to /dev/null shows that arrays give a 15% performance improvement for Python 2.7.14. However, arrays significantly decrease performance for Python 3.

_read_buf(fd)

Read self._bufsize into a string of bytes, handling EAGAIN and EIO. This will only call os.read() once, so the caller should call this method in a loop until either None or an empty string of bytes is returned. An empty string of bytes indicates EOF. None indicates EAGAIN.

NOTE: os.read() will be called regardless of the event flags,

since otherwise data may be lost (see bug #531724).

Parameters

fd (int) – file descriptor (non-blocking mode required)

Return type

bytes or None

Returns

A string of bytes, or None

_registered
_start()
_start_hook()
_start_listeners
_unlock()
_unlock_future
_unregister()
_wait_hook()

Call this method after the task completes, just before returning the returncode from wait() or poll(). This hook is used to trigger exit listeners when the returncode first becomes available.

_wait_loop(timeout=None)
_was_cancelled()

If cancelled, set returncode if necessary and return True. Otherwise, return False.

addExitListener(f)

The function will be called with one argument, a reference to self.

addStartListener(f)

The function will be called with one argument, a reference to self.

async_unlock()

Release the lock asynchronously. Release notification is available via the add_done_callback method of the returned Future instance.

Returns

Future, result is None

async_wait()

Wait for returncode asynchronously. Notification is available via the add_done_callback method of the returned Future instance.

Returns

Future, result is self.returncode

background
cancel()

Cancel the task, but do not wait for exit status. If asynchronous exit notification is desired, then use addExitListener to add a listener before calling this method. NOTE: Synchronous waiting for status is not supported, since it would be vulnerable to hitting the recursion limit when a large number of tasks need to be terminated simultaneously, like in bug #402335.

cancelled
copy()

Create a new instance and copy all attributes defined from __slots__ (including those from inherited classes).

isAlive()
path
poll()
removeExitListener(f)
removeStartListener(f)
returncode
scheduler
start()

Start an asynchronous task and then return as soon as possible.

wait()

Wait for the returncode attribute to become ready, and return it. If the returncode is not ready and the event loop is already running, then the async_wait() method should be used instead of wait(), because wait() will raise asyncio.InvalidStateError in this case.

Return type

int

Returns

the value of self.returncode

class _emerge.AsynchronousLock._LockThread(**kwargs)

Bases: _emerge.AbstractPollTask.AbstractPollTask

This uses the portage.locks module to acquire a lock asynchronously, using a background thread. After the lock is acquired, the thread writes to a pipe in order to notify a poll loop running in the main thread.

If the threading module is unavailable then the dummy_threading module will be used, and the lock will be acquired synchronously (before the start() method returns).

_async_wait()

Subclasses call this method in order to invoke exit listeners when self.returncode is set. Subclasses may override this method in order to perform cleanup. The default implementation for this method simply calls self.wait(), which will immediately raise an InvalidStateError if the event loop is running and self.returncode is None.

_bufsize = 4096
_cancel()

Subclasses should implement this, as a template method to be called by AsynchronousTask.cancel().

_cancelled_returncode = -2
_exit_listener_cb(listener)
_exit_listener_handles
_exit_listeners
_force_dummy
_lock_obj
_poll()
_read_array(f)

NOTE: array.fromfile() is used here only for testing purposes, because it has bugs in all known versions of Python (including Python 2.7 and Python 3.2). See PipeReaderArrayTestCase.

A benchmark that copies bytes from /dev/zero to /dev/null shows that arrays give a 15% performance improvement for Python 2.7.14. However, arrays significantly decrease performance for Python 3.

_read_buf(fd)

Read self._bufsize into a string of bytes, handling EAGAIN and EIO. This will only call os.read() once, so the caller should call this method in a loop until either None or an empty string of bytes is returned. An empty string of bytes indicates EOF. None indicates EAGAIN.

NOTE: os.read() will be called regardless of the event flags,

since otherwise data may be lost (see bug #531724).

Parameters

fd (int) – file descriptor (non-blocking mode required)

Return type

bytes or None

Returns

A string of bytes, or None

_registered
_run_lock()
_run_lock_cb()
_start()
_start_hook()
_start_listeners
_thread
_unlock()
_unlock_future
_unregister()
_wait_hook()

Call this method after the task completes, just before returning the returncode from wait() or poll(). This hook is used to trigger exit listeners when the returncode first becomes available.

_wait_loop(timeout=None)
_was_cancelled()

If cancelled, set returncode if necessary and return True. Otherwise, return False.

addExitListener(f)

The function will be called with one argument, a reference to self.

addStartListener(f)

The function will be called with one argument, a reference to self.

async_unlock()

Release the lock asynchronously. Release notification is available via the add_done_callback method of the returned Future instance.

Returns

Future, result is None

async_wait()

Wait for returncode asynchronously. Notification is available via the add_done_callback method of the returned Future instance.

Returns

Future, result is self.returncode

background
cancel()

Cancel the task, but do not wait for exit status. If asynchronous exit notification is desired, then use addExitListener to add a listener before calling this method. NOTE: Synchronous waiting for status is not supported, since it would be vulnerable to hitting the recursion limit when a large number of tasks need to be terminated simultaneously, like in bug #402335.

cancelled
copy()

Create a new instance and copy all attributes defined from __slots__ (including those from inherited classes).

isAlive()
path
poll()
removeExitListener(f)
removeStartListener(f)
returncode
scheduler
start()

Start an asynchronous task and then return as soon as possible.

wait()

Wait for the returncode attribute to become ready, and return it. If the returncode is not ready and the event loop is already running, then the async_wait() method should be used instead of wait(), because wait() will raise asyncio.InvalidStateError in this case.

Return type

int

Returns

the value of self.returncode