On related note, check threadutil.py / async_syscmd. It uses QProcess and
gives callback when command has been completed (avoiding threads completely
due to Qt even loop integration)
def async_syscmd(cmd, onfinished):
proc = QtCore.QProcess()
def cmd_handler(exitstatus):
out = proc.readAllStandardOutput()
err = proc.readAllStandardError()
#print "got",out, "e", err, "r", exitstatus
onfinished(exitstatus, out, err)
proc.finished[int].connect(cmd_handler)
proc.start(cmd)
#garbage.append(proc)
On Wed, Oct 16, 2013 at 5:18 PM, Edward K. Ream <[email protected]> wrote:
> The g.execute_shell_commands function executes a list of shell commands,
> each in a separate processes.
> *Important*: unlike subprocess.call, each command in the list is a
> separate command (commands are not concatenated).
>
> This function waits for each command to complete, unless the command
> starts with '&'. For example::
>
> g.execute_shell_commands(['echo hello','echo world','&pwd'])
>
> Here it is::
>
> def execute_shell_commands(commands,trace = False):
> '''
> Execute each shell command in a separate process.
> Wait for each command to complete, except those starting with '&'
> '''
> for command in commands:
> wait = not command.startswith('&')
> if command.startswith('&'): command = command[1:].strip()
> if trace: g.trace('wait',wait,'command',command)
> proc = subprocess.Popen(command,shell=True)
> if wait: proc.communicate()
>
> I have used g.execute_shell_command to great effect in @button make-sphinx
> in LeoDocs.leo.
> I'll discuss this next in a reply to the thread "@button make-html
> @key=Alt-period".
>
> Edward
>
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/leo-editor.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.