moobius.core.wand#

Module-level functions#

sigint_handler#

Exits using a special error code that the parent process will recognize as a “Ctrl+C” interrupt..

Signature:

  • **sigint_handler**(signal, frame)

Parameters:

  • __signal:__ Integer signal.

  • __frame:__ Stack frame.

Returns:

  • The os._exit.

Raises:

  • (this function does not raise any notable errors)

Class MoobiusWand#

Starts and manages services. It can also be used to send messages to a service using the spell() function or the async aspell() function.

The typical use-case and suggested file paths:
>>> wand = MoobiusWand()
>>> handle = wand.run(MyService, config_path="config/service.json", db_config_path="config/db.json",
>>>                   log_file="logs/service.log", error_log_file="logs/error.log", terminal_log_level="INFO",
>>>                   is_agent=False, background=True)
>>> wand.spell(handle, xyz_message) # Use to send data to the service.

MoobiusWand.run_job#

Runs service.start(), which blocks in an infinite loop, using asyncio.

Signature:

  • **MoobiusWand.run_job**(service)

Parameters:

  • __service:__ Moobius service.

Returns:

  • The Never.

Raises:

  • (this function does not raise any notable errors)

MoobiusWand.run#

Starts a service or agent, either on the same process in a blocking infinite loop or on another process.

Signature:

  • **MoobiusWand.run**(self, cls, background, kwargs)

Parameters:

  • __cls:__ A subclass of the Moobius class but NOT an instance.

  • __background:__ If True, runs on another Process.

  • __kwargs=False:__ Kwargs passed to the constructor of cls.

Returns:

  • None.

Raises:

  • (this function does not raise any notable errors)

Example:

>>> wand = MoobiusWand() >>> handle = wand.run( >>> MyService, >>> log_file="logs/service.log", >>> error_log_file="logs/error.log", >>> terminal_log_level="INFO", >>> config_path="config/service.json", >>> db_config_path="config/db.json", >>> background=True)

MoobiusWand.stop_all#

Stops all processes using the_process.kill().. Also stops the asyncio event loop.

Signature:

  • **MoobiusWand.stop_all**(self, force_exit)

Parameters:

  • __force_exit=False:__ N option to force-quit.

Returns:

  • The exit.

Raises:

  • (this function does not raise any notable errors)

MoobiusWand.spell#

Sends a message to a service by putting to it’s aioprocessing.AioQueue().

Signature:

  • **MoobiusWand.spell**(self, handle, obj)

Parameters:

  • __handle:__ The handle of the service created by the run() function.

  • __obj:__ The message to be sent.

Returns:

  • None.

Raises:

  • (this function does not raise any notable errors)

Example:

>>> wand = MoobiusWand() >>> handle = wand.run(...) >>> wand.spell(handle=handle, obj=MessageDown(message_type="test", context={"sender": "1", "recipients": ["2"]}))

MoobiusWand.aspell#

Async version of spell(), uses q.coro_put(obj) instead of q.put(obj) where q = self.services[handle].queue..

Signature:

  • **MoobiusWand.aspell**(self, handle, obj)

Parameters:

  • __handle:__ Handle int.

  • __obj:__ The generic pickleable object.

Returns:

  • None.

Raises:

  • (this function does not raise any notable errors)

Class attributes#

Internals#