Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] document system command configuration better, especially the async flag #2487

Closed
tiosolid opened this issue Mar 18, 2018 · 3 comments
Closed

Comments

@tiosolid
Copy link

@tiosolid tiosolid commented Mar 18, 2018

What were you doing?

Creating a new command in the system menu while using a script that does not return (I.E. have something like an while True: inside it) stalls the interface since it waits forever for the /api/system/commands/custom request to finish.

Tried to run the python script using a bash sh file that exit 0 but it still didnt work. I need this infinite loop since I'm using PWM and the script needs to run until killed via another script (I used a "flag" file so the scripts end gracefully).

Stuff that I tried (and didn't work)

  • Running the .py script directly in the config.yaml;
  • Running the .py script using a .sh script (like python /home/pi/script.py &);
  • Running the .py script in the config.yaml using python /home/pi/script.py &;

Source code of the "start" script (running this stalls the interface forever):

import RPi.GPIO as IO
import time
import os.path

IO.setwarnings(False)
IO.setmode (IO.BCM)
IO.setup(18,IO.OUT)
p = IO.PWM(18,100)

open("/home/pi/lighton.flag", "a").close()
p.start(100)
p.ChangeDutyCycle(100)
while os.path.isfile("/home/pi/lighton.flag"):
        pass

p.ChangeDutyCycle(0)
p.stop()

Source code of the "stop" script (this one always works and does not stall the web interface):

import os

if os.path.isfile("/home/pi/lighton.flag"):
        os.remove("/home/pi/lighton.flag")

Source code of the bash script:

#!/bin/bash

python /home/pi/lighton.py &
exit 0

Source code of the relevant part of my config.yaml file:

system:
  actions:
  - action: streamon
    command: sudo service webcamd start
    confirm: false
    name: Start video stream
  - action: streamoff
    command: sudo service webcamd stop
    confirm: false
    name: Stop video stream
  - action: lighton
    command: /home/pi/lighton.sh
    confirm: false
    name: Turn printer lights on
  - action: lightoff
    command: python /home/pi/lightoff.py
    confirm: false
    name: Turn printer lights off

Note that running these scripts manually from the terminal works.

What did you expect to happen?

Normal system command behavior (run and return a green success message since the script does not raise an exception).

What happened instead?

Interface is stalled forever while waiting for the request to finish.

Did the same happen when running OctoPrint in safe mode?

Yes

Version of OctoPrint

1.3.6

Operating System running OctoPrint

OctoPi with a Raspberry Pi 3.

Browser and version of browser, operating system running browser

Chrome 65.0 in Windows 10 64-bits

Note: I removed all the other stuff about the printer and logs from the bug report since nothing different is logged and not having a printer connected does not change this behavior.

@GitIssueBot

This comment has been minimized.

Copy link
Collaborator

@GitIssueBot GitIssueBot commented Mar 18, 2018

Hi @tiosolid,

It looks like there is some information missing from your bug report that will be needed in order to solve the problem. Read the Contribution Guidelines which will provide you with a template to fill out here so that your bug report is ready to be investigated (I promise I'll go away then too!).

If you did not intend to report a bug but wanted to request a feature or brain storm about some kind of development, please take special note of the title format to use as described in the Contribution Guidelines.

Please do not abuse the bug tracker as a support forum - that can be found at discourse.octoprint.org. Go there for any kind of issues with network connectivity, webcam functionality, printer detection or any other kind of such support requests or general questions.

Also make sure you are at the right place - this is the bug tracker of the official version of OctoPrint, not the Raspberry Pi image OctoPi nor any unbundled third party OctoPrint plugins or unofficial versions. Make sure too that you have read through the Frequently Asked Questions and searched the existing tickets for your problem - try multiple search terms please.

I'm marking this one now as needing some more information. Please understand that if you do not provide that information within the next two weeks (until 2018-04-01 01:10 UTC) I'll close this ticket so it doesn't clutter the bug tracker. This is nothing personal, so please just be considerate and help the maintainers solve this problem quickly by following the guidelines linked above. Remember, the less time the devs have to spend running after information on tickets, the more time they have to actually solve problems and add awesome new features. Thank you!

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being, so don't expect any replies from me :) Your ticket is read by humans too, I'm just not one of them.

@foosel

This comment has been minimized.

Copy link
Owner

@foosel foosel commented Mar 18, 2018

You need to set the async flag to true for commands that don't return. Needs to be documented. Turning this into a documentation request.

@foosel foosel changed the title Using custom system commands with a script that do not return stalls the OctoPrint Web Interface [Request] document system command configuration better, especially the async flag Mar 18, 2018
@tiosolid

This comment has been minimized.

Copy link
Author

@tiosolid tiosolid commented Mar 18, 2018

Using async worked flawlessly. Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.