Home
Ratchet Library :: API Reference
API  ·  Manual

Module ratchet

The purpose of the ratchet library is to provide a generic socket control mechanism for large numbers of sockets without using threads or losing the ease of synchronous socket programming. Along with networking, the library provides a sort of kernel to allow side-by-side execution of different streams of logic.

Functions

get_method (self) Returns the polling method used behind-the-scenes by libevent.
get_num_threads (self) Returns the number of active threads the ratchet object is managing.
get_space (self, thread, default) Gets the table (see ratchet.thread.space()) associated with the given thread.
loop (self) Processes thread events in a loop.
loop_once (self, noblock) Executes one iteration of event processing.
new (entry, errh) Constructs and returns a new ratchet object.


Functions

get_method (self)
Returns the polling method used behind-the-scenes by libevent.

Parameters

  • self: the ratchet object.

Return value:

a string identifying the kernel event mechanism (kqueue, epoll, etc.).
get_num_threads (self)
Returns the number of active threads the ratchet object is managing. This includes threads that are currently running and threads that are paused, but not any that have completed or errored.

Parameters

  • self: the ratchet object.

Return value:

the number of active threads.
get_space (self, thread, default)
Gets the table (see ratchet.thread.space()) associated with the given thread.

Parameters

  • self: the ratchet object.
  • thread: the thread to get the table for.
  • default: if given, this table (or any object) will be set and returned if no other space has already been set for the thread.
loop (self)
Processes thread events in a loop. This function simply runs loop_once() with blocking until it returns false.

Parameters

  • self: the ratchet object.
loop_once (self, noblock)
Executes one iteration of event processing. This may include starting a new thread or resuming one that was paused manually or by an event. This function may block unless noblock is given true.

Parameters

  • self: the ratchet object.
  • noblock: given as true, this function will not block waiting for events.

Return value:

false if all threads have completed execution, true otherwise.
new (entry, errh)
Constructs and returns a new ratchet object. This also creates a new libevent control structure that is freed when the object is collected.

Parameters

  • entry: called initially as the entry-point ratchet thread.
  • errh: called after an error in a ratchet thread before the stack is unwound. It is given two arguments, the error and the thread.

Return value:

a new ratchet object.