diff options
author | John Garland <johnnybg+deluge@gmail.com> | 2012-03-01 18:15:09 +1100 |
---|---|---|
committer | John Garland <johnnybg+deluge@gmail.com> | 2012-03-02 12:57:47 +1100 |
commit | b0029517eb7a0f122adfc6c8231bf404d277623b (patch) | |
tree | 0471e707633872ee51fa18c7ea8d85334006edd3 | |
parent | 2ae936df44f59544c9e05357a4fea1ef5fbd0603 (diff) | |
download | deluge-b0029517eb7a0f122adfc6c8231bf404d277623b.tar.gz deluge-b0029517eb7a0f122adfc6c8231bf404d277623b.tar.bz2 deluge-b0029517eb7a0f122adfc6c8231bf404d277623b.zip |
Execute: make running commands asynchronous
This prevents deluge from hanging while it waits
for a command to finish.
This also prevents a deadlock from occuring
(c.f. warning at
http://docs.python.org/library/subprocess.html#subprocess.Popen.wait)
-rw-r--r-- | deluge/plugins/execute/execute/core.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/deluge/plugins/execute/execute/core.py b/deluge/plugins/execute/execute/core.py index 52bfbc55f..9a4b3422b 100644 --- a/deluge/plugins/execute/execute/core.py +++ b/deluge/plugins/execute/execute/core.py @@ -36,7 +36,7 @@ import os import time import hashlib -from subprocess import Popen, PIPE +from twisted.internet.utils import getProcessValue from deluge.log import LOG as log from deluge.plugins.pluginbase import CorePluginBase @@ -110,15 +110,18 @@ class Core(CorePluginBase): log.debug("[execute] Running commands for %s", event) + def log_error(exit_code, command): + if exit_code: + log.warn("[execute] command '%s' failed with exit code %d", command, exit_code) + # Go through and execute all the commands for command in self.config["commands"]: if command[EXECUTE_EVENT] == event: command = os.path.expandvars(command[EXECUTE_COMMAND]) command = os.path.expanduser(command) log.debug("[execute] running %s", command) - p = Popen([command, torrent_id, torrent_name, save_path], stdin=PIPE, stdout=PIPE, stderr=PIPE) - if p.wait() != 0: - log.warn("Execute command failed with exit code %d", p.returncode) + d = getProcessValue(command, (torrent_id, torrent_name, save_path), env=os.environ) + d.addCallback(log_error, command) def disable(self): self.config.save() |