feat: gcode_shell_command: option to terminate or not subprocess #237

Open
ruben-podadera wants to merge 1 commits from ruben-podadera/master into master
ruben-podadera commented 2022-08-29 23:29:32 +02:00 (Migrated from github.com)

Hi @th33xitus,

I'm using gcode_shell_command to take a timelapse (with gphoto and an external camera plugged in usb). I set as many camera settings as possible in manual mode so the photography process is quite fast (less than 1s). But after that, I copy the image file to a network drive. This part takes up to 10 seconds.

I dont want to pause the print job for something that can be made in background. So I just added a config for the gcode_shell_command in order to let the subprocess continue if I want to.

I know that this is far from perfect (could may be add a second "safety" timeout to actually terminate the subprocess) but may be it could help other users.

Anyway, thank you for you work. Regards

Hi @th33xitus, I'm using `gcode_shell_command` to take a timelapse (with gphoto and an external camera plugged in usb). I set as many camera settings as possible in manual mode so the photography process is quite fast (less than 1s). But after that, I copy the image file to a network drive. This part takes up to 10 seconds. I dont want to pause the print job for something that can be made in background. So I just added a config for the `gcode_shell_command` in order to let the subprocess continue if I want to. I know that this is far from perfect (could may be add a second "safety" timeout to actually terminate the subprocess) but may be it could help other users. Anyway, thank you for you work. Regards
ruben-podadera commented 2022-08-29 23:33:45 +02:00 (Migrated from github.com)

I can update the doc if you want to

I can update the doc if you want to
dw-0 commented 2022-09-08 09:18:29 +02:00 (Migrated from github.com)

Hi, thanks for contributing.
Can you give me an example where you make use of that new option?

I haven't tried it yet but is it not possible to call an external shell script and inside there, start subprocesses as you wish?

In any case, if your idea makes sense and we merge it, we definitely need an example in the docs i would say.

Hi, thanks for contributing. Can you give me an example where you make use of that new option? I haven't tried it yet but is it not possible to call an external shell script and inside there, start subprocesses as you wish? In any case, if your idea makes sense and we merge it, we definitely need an example in the docs i would say.
ruben-podadera commented 2022-10-14 14:56:26 +02:00 (Migrated from github.com)

Hi ! Sorry for the long answer, i'll try to be quicker now.

I use this command to take pictures with gphoto.

macro_timelapse.cfg :

[gcode_shell_command gphoto_take_frame]
command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh
timeout: 2.
verbose: True
terminate: False

gphoto_take_snapshot.sh :

#!/bin/sh

# UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds)
UUID=`cat /tmp/uuid`
DIR=/mnt/some-network-drive/klipper-timelapses/$UUID
mkdir -p $DIR
COUNT=`ls -l $DIR | egrep -v "^total " | wc -l`
COUNT=$((COUNT+1))
sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg

With the camera model I have, once the picture is taken, it takes a while before gphoto command returns. For what I've measured, the picture is taken around 1s but the command takes around 9s to return. Thats a lot of time for each layer. Thats why I set timeout: 2. and terminate: False

Hi ! Sorry for the long answer, i'll try to be quicker now. I use this command to take pictures with gphoto. macro_timelapse.cfg : ```ini [gcode_shell_command gphoto_take_frame] command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh timeout: 2. verbose: True terminate: False ``` gphoto_take_snapshot.sh : ```shell #!/bin/sh # UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds) UUID=`cat /tmp/uuid` DIR=/mnt/some-network-drive/klipper-timelapses/$UUID mkdir -p $DIR COUNT=`ls -l $DIR | egrep -v "^total " | wc -l` COUNT=$((COUNT+1)) sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg ``` With the camera model I have, once the picture is taken, it takes a while before gphoto command returns. For what I've measured, the picture is taken around 1s but the command takes around 9s to return. Thats a lot of time for each layer. Thats why I set `timeout: 2.` and `terminate: False`
Creo2005 commented 2024-02-19 14:20:14 +01:00 (Migrated from github.com)

Привіт ! Вибачте за довгу відповідь, зараз я постараюся бути швидким.

Я використовую цю команду для фотографування за допомогою gphoto.

macro_timelapse.cfg :

[gcode_shell_command gphoto_take_frame]
command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh
timeout: 2.
verbose: True
terminate: False

gphoto_take_snapshot.sh :

#!/bin/sh

# UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds)
UUID=`cat /tmp/uuid`
DIR=/mnt/some-network-drive/klipper-timelapses/$UUID
mkdir -p $DIR
COUNT=`ls -l $DIR | egrep -v "^total " | wc -l`
COUNT=$((COUNT+1))
sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg

З моєї моделі камери після того, як знімок буде зроблено, команда gphoto повернеться через деякий час. Відповідно до моїх вимірювань знімок робиться приблизно за 1 с, але для повернення команди потрібно близько 9 с. Це багато для кожного часу шару. Ось чому я поставив timeout: 2.іterminate: False

Hi ! Sorry for the long answer, i'll try to be quicker now.

I use this command to take pictures with gphoto.

macro_timelapse.cfg :

[gcode_shell_command gphoto_take_frame]
command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh
timeout: 2.
verbose: True
terminate: False

gphoto_take_snapshot.sh :

#!/bin/sh

# UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds)
UUID=`cat /tmp/uuid`
DIR=/mnt/some-network-drive/klipper-timelapses/$UUID
mkdir -p $DIR
COUNT=`ls -l $DIR | egrep -v "^total " | wc -l`
COUNT=$((COUNT+1))
sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg

With the camera model I have, once the picture is taken, it takes a while before gphoto command returns. For what I've measured, the picture is taken around 1s but the command takes around 9s to return. Thats a lot of time for each layer. Thats why I set timeout: 2. and terminate: False

How does sudo work for you, I want to run a script for updating the firmware of the board, but sudo does not work for me, because it says that a password must be entered. sudo service klipper stop and sudo service klipper start not working.

> Привіт ! Вибачте за довгу відповідь, зараз я постараюся бути швидким. > > Я використовую цю команду для фотографування за допомогою gphoto. > > macro_timelapse.cfg : > > ```ini > [gcode_shell_command gphoto_take_frame] > command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh > timeout: 2. > verbose: True > terminate: False > ``` > > gphoto_take_snapshot.sh : > > ```shell > #!/bin/sh > > # UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds) > UUID=`cat /tmp/uuid` > DIR=/mnt/some-network-drive/klipper-timelapses/$UUID > mkdir -p $DIR > COUNT=`ls -l $DIR | egrep -v "^total " | wc -l` > COUNT=$((COUNT+1)) > sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg > ``` > > З моєї моделі камери після того, як знімок буде зроблено, команда gphoto повернеться через деякий час. Відповідно до моїх вимірювань знімок робиться приблизно за 1 с, але для повернення команди потрібно близько 9 с. Це багато для кожного часу шару. Ось чому я поставив `timeout: 2.`і`terminate: False` > Hi ! Sorry for the long answer, i'll try to be quicker now. > > I use this command to take pictures with gphoto. > > macro_timelapse.cfg : > > ```ini > [gcode_shell_command gphoto_take_frame] > command: sh /home/pi/klipper_config/gphoto_take_snapshot.sh > timeout: 2. > verbose: True > terminate: False > ``` > > gphoto_take_snapshot.sh : > > ```shell > #!/bin/sh > > # UUID is generated in start script. Its a unique number for the print (actually is a datetime is seconds) > UUID=`cat /tmp/uuid` > DIR=/mnt/some-network-drive/klipper-timelapses/$UUID > mkdir -p $DIR > COUNT=`ls -l $DIR | egrep -v "^total " | wc -l` > COUNT=$((COUNT+1)) > sudo gphoto2 --capture-image-and-download --filename=$DIR/$COUNT.jpg > ``` > > With the camera model I have, once the picture is taken, it takes a while before gphoto command returns. For what I've measured, the picture is taken around 1s but the command takes around 9s to return. Thats a lot of time for each layer. Thats why I set `timeout: 2.` and `terminate: False` How does sudo work for you, I want to run a script for updating the firmware of the board, but sudo does not work for me, because it says that a password must be entered. sudo service klipper stop and sudo service klipper start not working.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin ruben-podadera/master:ruben-podadera/master
git checkout ruben-podadera/master
Sign in to join this conversation.