Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the correct way to close a python batch job?
#1
Hi all,

I've been trying hard to get a batch script converted over from script-fu in Python but I'm struggling to get it to close the process as I can't seem to get it to close GIMP. The script runs but it won't kill the process so is making everything hang. 

I can't seem to find any docs on how to actually do some of this stuff, it seems that those that know, know and I'm not sure how to fill in the gaps in my knowledge. 

Up front I'm new to python but a long in the tooth coder in various other languages.

So my question is, what is the correct way to close GIMP these days?

I'm running GIMP 2.10.18 on Windows 10

This is roughly my command I'm running:

"C:\Program Files\GIMP 2\bin\gimp-console-2.10.exe" -id --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import mydynamicTextReplace;dynamicTextReplace.process('my_example_param_1')"

So far I've tried (yep I'm in cut and paste "lets see if this works" land at this point):

  1. Adding '-b (gimp-quit 0)' to the end of the command, this was a left over from the script-fu script and I think this fails as I've told it to use the python parser not script-fu?
  2. Adding '-b "pdb.gimp_quit(1)" ' to the end of the command, no luck with this one
  3. Adding '-b "gimp.quit(1)" ' to the end of the command, no luck with this one either
  4. Adding variations of "gimp.quit" and "pdb.quit" to the end of my script that I'm importing but these all seem to have zero effect
Thought and guidance? Are there any docs online about doing this sort of stuff better, it feels way to fumbling around in the dark to me and I've been at this several sessions now.

Many thanks in advance.
Reply
#2
In my trials I used -b 'pdb.gimp_quit(1)' and it worked (and you seem to be using my technique). if you open the Python-fu console and enter pdb.gimp_quit(1) Gimp indeed exits.

"Adding variations of "gimp.quit" and "pdb.quit" to the end of my script that I'm importing but these all seem to have zero effect": these shoud elicit error messages. So if they have zero effect they aren't even executed. Did you try to prove to yourself that your main code actually finishes?
Reply
#3
(03-25-2020, 12:06 AM)Ofnuts Wrote: In my trials I used -b 'pdb.gimp_quit(1)' and it worked (and you seem to be using my technique). if you open the Python-fu console and enter pdb.gimp_quit(1) Gimp indeed exits.

"Adding variations of "gimp.quit" and "pdb.quit" to the end of my script that I'm importing but these all seem to have zero effect": these shoud elicit error messages. So if they have zero effect they aren't even executed. Did you try to prove to yourself that your main code actually finishes?

Well thank you for the method, my script is a bit of a half baked monster of cut and paste examples I've found here and there from too many stackover flow quesitons/forum posts etc. to remember.

Good point on the script not working, that might be it, it has worked before but with all my hacking around that might not be the case and my focus on the lack of closing might be masking the issue. I'll take a look.

On that note any pointers on how to debug this stuff easier? I'm currently doing to "comment out everything and add it back in one line at a time" phase but its slow and missing some feedback. I can't seem to get any messages out of it either so even simple print statement debugging is out of my reach right now Sad
Reply
#4
(03-25-2020, 10:04 AM)sethsdad Wrote:
(03-25-2020, 12:06 AM)Ofnuts Wrote: In my trials I used -b 'pdb.gimp_quit(1)' and it worked (and you seem to be using my technique). if you open the Python-fu console and enter pdb.gimp_quit(1) Gimp indeed exits.

"Adding variations of "gimp.quit" and "pdb.quit" to the end of my script that I'm importing but these all seem to have zero effect": these shoud elicit error messages. So if they have zero effect they aren't even executed. Did you try to prove to yourself that your main code actually finishes?

Well thank you for the method, my script is a bit of a half baked monster of cut and paste examples I've found here and there from too many stackover flow quesitons/forum posts etc. to remember.

Good point on the script not working, that might be it, it has worked before but with all my hacking around that might not be the case and my focus on the lack of closing might be masking the issue. I'll take a look.

On that note any pointers on how to debug this stuff easier? I'm currently doing to "comment out everything and add it back in one line at a time" phase but its slow and missing some feedback. I can't seem to get any messages out of it either so even simple print statement debugging is out of my reach right now Sad

See here: https://www.gimp-forum.net/Thread-Debugg...in-Windows

Personally, I'm on Linux, so I can start Gimp in a terminal and see its output and my Python print statements there while it runs. Going to Linux has definitely made things a lot easier.
Reply
#5
That page of how to debug is genius! Thats what I've been missing. Thank you so much Smile

Found the error, was referencing a file that didn't exist anymore and I had a blank line in my method (is that a python thing though or a python console thing?)

Many thanks
Reply
#6
Empty lines are OK, blank lines are OK if they are coherent with indentation (a tab in the middle of space-indented lines may trigger something). But just trying to run the script outside of Gimp would have shown that (as well as other blatant errors such as unbalanced parentheses...).
Reply


Forum Jump: