PDA

View Full Version : How to close a terminal with a python script?



[o_0] Rob
June 20th, 2009, 01:25 PM
I'm using cron to run the command

python myscript.py args

The script runs OK, but it leaves a terminal open with message

Press ENTER to continue and close this window.

I would prefer not having an useless terminal stay open.

1. What can I add to the python script to get the terminal to close? The script is probably not relevant but if you're interested it can be seen here (http://dev.deluge-torrent.org/ticket/382#comment:4).
2. Alternatively, what can I add to the cron command? I've tried adding "exit" but it doesn't help.

python myscript.py args | exit

I suspect the solution is trivial, but I'm new to ubuntu and programming. Thanks in advance for any help :)

Cammy
June 20th, 2009, 01:27 PM
killall gnome-terminal ?

[o_0] Rob
June 20th, 2009, 01:37 PM
killall gnome-terminal ?

Thanks for the help Cammy :)

I've just tried that. It closes every terminal that may be open though, so it's not ideal. Is there a way to only close one terminal?

kaivalagi
June 20th, 2009, 02:05 PM
Try adding an exit(0) underneath the set_config line in the script as below. It might work...worth a try...


#!/usr/bin/python
from sys import argv, exit
import logging

logging.disable(logging.ERROR)

if (len(argv) < 2):
print "Need value for max_active_limit"
exit(2)

if (argv[1].isdigit()):
from deluge.ui.client import sclient as client

client.set_core_uri()
client.set_config({'max_active_limit': int(argv[1])})
exit(0)

else:
print "Invalid max_active_limit value"
exit(3)

pokerbirch
June 20th, 2009, 02:16 PM
Surely the script should exit on it's own, without needing to explicitly use the Exit() command? I would check the code in your script. Something is not right.

[o_0] Rob
June 20th, 2009, 03:09 PM
Try adding an exit(0) underneath the set_config line in the script as below. It might work...worth a try...


Thanks kaivalagi; unfortunately no luck.

After some more searching, I've found someone with the same problem here (http://ubuntuforums.org/showthread.php?t=1113168). No solution though.

[o_0] Rob
June 20th, 2009, 03:13 PM
Thanks for everyone's suggestions. I've found a very trivial solution. Add "&& exit" to the cron command.