kiauh icon indicating copy to clipboard operation
kiauh copied to clipboard

feat: gcode_shell_command: option to terminate or not subprocess

Open ruben-podadera opened this issue 1 year ago • 4 comments

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 avatar Aug 29 '22 21:08 ruben-podadera

I can update the doc if you want to

ruben-podadera avatar Aug 29 '22 21:08 ruben-podadera

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.

dw-0 avatar Sep 08 '22 07:09 dw-0

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

ruben-podadera avatar Oct 14 '22 12:10 ruben-podadera