API Reference

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

Public API


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.


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.

Closes this context and release the memory from C area.


Starts the polling thread.


Stops the polling thread.

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


Triggers the callback functions.

This method is expected to be called from C area.


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.

Raises a runtime error from the specified description and errno.


Checks the return value from C area.

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