From 4963a4b849a6cd3041fe6c0e2a482c7975438f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 24 Jul 2018 17:44:59 +0200 Subject: [PATCH] docs: warning re expensive code in gcode hooks --- docs/plugins/hooks.rst | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index e1b0afa64..a1f125064 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -402,6 +402,13 @@ octoprint.comm.firmware.info ``firmware_name`` will be ``Some Firmware Name`` in this case. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within these handlers as + you will effectively block the receive loop, causing the communication with the printer to stall. + + This includes I/O of any kind. + :param object comm_instance: The :class:`~octoprint.util.comm.MachineCom` instance which triggered the hook. :param str firmware_name: The name of the parsed capability :param dict firmware_data: All data contained in the ``M115`` report @@ -421,6 +428,13 @@ octoprint.comm.firmware.capabilities Note that hook handlers will be called once per received capability line. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within these handlers as + you will effectively block the receive loop, causing the communication with the printer to stall. + + This includes I/O of any kind. + :param object comm_instance: The :class:`~octoprint.util.comm.MachineCom` instance which triggered the hook. :param str capability: The name of the parsed capability :param bool enabled: Whether the capability is reported as enabled or disabled @@ -440,6 +454,13 @@ octoprint.comm.protocol.action No returned value is expected. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within your handlers as + you will effectively block the receive loop, causing the communication with the printer to stall. + + This includes I/O of any kind. + **Example:** Logs if the ``custom`` action (``// action:custom``) is received from the printer's firmware. @@ -477,6 +498,13 @@ This describes actually two hooks: trigger the *actual execution* of whatever functionality lies behind a given @ command, similar to :ref:`the action command hook `. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within your handlers as + you will effectively block the send/receive loops, causing the communication with the printer to stall. + + This includes I/O of any kind. + **Example** Pause the print on ``@wait`` (this mirrors the implementation of the built-in ``@pause`` command, just with a @@ -623,6 +651,13 @@ This describes actually four hooks: Note: Only one command of a given ``cmd_type`` (other than None) may be queued at a time. Trying to rewrite the ``cmd_type`` to one already in the queue will give an error. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within these handlers as + you will effectively block the send loop, causing the communication with the printer to stall. + + This includes I/O of any kind. + **Example** The following hook handler replaces all ``M107`` ("Fan Off", deprecated) with an ``M106 S0`` ("Fan On" with speed @@ -658,6 +693,13 @@ octoprint.comm.protocol.gcode.received empty string as the received line. Note that Python functions will also automatically return ``None`` if an empty ``return`` statement is used or just nothing is returned explicitly from the handler. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within these handlers as + you will effectively block the receive loop, causing the communication with the printer to stall. + + This includes I/O of any kind. + **Example:** Looks for the response of an ``M115``, which contains information about the ``MACHINE_TYPE``, among other things. @@ -687,6 +729,13 @@ octoprint.comm.protocol.gcode.error Plugins might utilize this hook to handle errors generated by the printer that are recoverable in one way or the other and should not trigger the normal handling that assumes the worst. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within these handlers as + you will effectively block the receive loop, causing the communication with the printer to stall. + + This includes I/O of any kind. + **Example:** Looks for error messages containing "fan error" or "bed missing" (ignoring case) and marks them as handled by the @@ -762,6 +811,13 @@ octoprint.comm.protocol.temperatures.received additional sanity checking to be applied and invalid values to be filtered out. If a handler returns an empty dictionary or ``None``, no further processing will take place. + .. warning:: + + Make sure to not perform any computationally expensive or otherwise long running actions within these handlers as + you will effectively block the receive loop, causing the communication with the printer to stall. + + This includes I/O of any kind. + **Example** The following example shows how to filter out actual temperatures that are outside a sane range of 1°C to 300°C.