API Reference

For most users, please use the public API instead of the internal one.

Public API

orphanage.exit_when_orphaned()

Let the current process exit when it was orphaned.

Calling multiple times and calling-and-forking are both safe. But this is not a thread safe function. Never call it concurrently.

Internal API

class orphanage.poll.Context(callbacks=None, suicide_instead=False)

The context of orphans polling which acts as the CFFI wrapper.

Caution

It is dangerous to use this class directly except you are familiar with the implementation of CPython and you know what you are doing clearly. It is recommended to use the Public API instead, for most users.

The context must be closed via close() or the memory will be leaked.

Parameters:callbacks – Optional. The list of callback functions. A callback function will be passed one parameter, the instance of this context. Be careful, never invoking any Python built-in and C/C++ extended functions which use the Py_BEGIN_ALLOW_THREADS, such as os.close and all methods on this context, to avoid from deadlock and other undefined behaviors.
close()

Closes this context and release the memory from C area.

start()

Starts the polling thread.

stop()

Stops the polling thread.

Don’t forget to release allocated memory by calling close() if you won’t use it anymore.

trigger_callbacks()

Triggers the callback functions.

This method is expected to be called from C area.

orphanage.poll.orphanage_poll_routine_callback(ptr)

The external callback function of CFFI.

This function invokes the Context.trigger_callbacks() method.

Parameters:ptr – The C pointer of context.
Returns:0 for nonerror calls.
orphanage.poll.perror(description)

Raises a runtime error from the specified description and errno.

orphanage.poll.raise_for_return_value(return_value)

Checks the return value from C area.

A runtime error will be raised if the return value is nonzero.