Forums

Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum Python Worker : sendError() calls

  • Python Worker : sendError() calls

    Posted by Nathanaël on August 18, 2023 at 11:55 am

    Using the sample library for the Python Worker, I only modified the omnis_tes/main.py script this way :

    from omnis_calls import sendResponse, sendError
    def test(param):
    return sendError({'unicode': 'Error'})

    But when I run the script with the sample library, it calls the wtest.$pyWorkerComplete method … Am i missing something? 🤔

    • This discussion was modified 6 months, 1 week ago by  Nathanaël. Reason: Formatting code
    Andreas Pfeiffer replied 6 months, 1 week ago 3 Members · 7 Replies
  • 7 Replies
  • Nathanaël

    Member
    August 18, 2023 at 12:03 pm

    To be more precise, it’s the oPyWorker.$methodreturn() method that seems to receive the sendError call :

  • Andreas Pfeiffer

    Administrator
    August 18, 2023 at 12:14 pm

    Hi Nathanaël,

    I would think this is due to asynchronous execution. Omnis starts the worker and continues to execute that method. Therefore you need to have a callback that can be used to get the result from Python.

    Best,

    Andreas

    • Nathanaël

      Member
      August 18, 2023 at 1:40 pm

      Hi Andreas.

      Not sure what you mean, because the $methoderror and $methodreturn functions of the Python Worker Object are effectively called asynchronously.

      As discussed below, the problem seems to be that we are not able to explicitely call sendError from the Python script (thus the Omnis object’s $methoderror function), in a controlled / catched exception.

      • Nathanaël

        Member
        August 18, 2023 at 1:49 pm

        Sorry, let me clarify:

        * the problem seems to be that when explicitely calling sendError from the Python script it calls $methodreturn instead of $methoderror in the Omnis object, thus preventing us from managing python catched exception in a controlled way.

        • Andreas Pfeiffer

          Administrator
          August 18, 2023 at 2:37 pm

          Hi Nathanaël,

          I think Götz already covered this.

          Best,

          Andreas

  • Götz Krija

    Member
    August 18, 2023 at 1:03 pm

    Hi Nathanaël,

    I do not have much experience with Python, but the manual says you can import omnis_calls in your main.py and use sendResponse or sendError if required. So you are probably right and the oPyWorker.$methoderror() method should receive the error in this case.

    I have put in a fault for engineering to investigate further. The reference is ST/EC/1804

    As a workaround you can probably raise an exception in the Python script:

    raise Exception(“this is an error”)

    Götz

    • Nathanaël

      Member
      August 18, 2023 at 1:36 pm

      @Götz Krija

      Thanks for raising the fault.

      Indeed I wrote another Python script that deliberately raises an exeption that is not catched, and it is actually calling the $methoderror method in the PyWorker object this time.

      But that’s not practical, to be honest, because I would rather have the ability to catch exceptions in the python script, and use the sendError() method if necessary.

Log in to reply.