aboutsummaryrefslogtreecommitdiffstats
path: root/IRC
diff options
context:
space:
mode:
authorEUcancER <root@euer.krebsco.de>2012-04-18 23:11:33 +0200
committerEUcancER <root@euer.krebsco.de>2012-04-18 23:11:33 +0200
commit1556d2987ca039ea9a1a28c9c6921162dad3730c (patch)
treee1d926e2f05b53b580fa60e3af53ae8bf1cccb35 /IRC
parent2b1eb54f10a7babd114e216f1be32cb6f313ec46 (diff)
live feedback from subprocess, shorter timeout
Diffstat (limited to 'IRC')
-rwxr-xr-xIRC/asybot.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/IRC/asybot.py b/IRC/asybot.py
index 17f9cb3..6edc13b 100755
--- a/IRC/asybot.py
+++ b/IRC/asybot.py
@@ -109,7 +109,7 @@ class asybot(asychat):
def PRIVMSG(text):
msg = 'PRIVMSG %s :%s' % (','.join(params), text)
self.push(msg)
- sleep(2)
+ sleep(1)
def ME(text):
PRIVMSG('ACTION ' + text + '')
@@ -128,7 +128,7 @@ class asybot(asychat):
from os.path import realpath, dirname, join
from subprocess import Popen as popen, PIPE
-
+ from time import time
Reaktor_dir = dirname(realpath(dirname(__file__)))
public_commands = join(Reaktor_dir, 'public_commands')
command = join(public_commands, _command)
@@ -137,29 +137,27 @@ class asybot(asychat):
env = {}
args = []
+ start = time()
if _argument != None:
env['argument'] = _argument
args = shlex.split(_argument)
try:
- p = popen([command] + args, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env)
+ p = popen([command] + args,bufsize=1, stdout=PIPE, stderr=PIPE, env=env)
except OSError, error:
ME('brain damaged')
log.error('OSError@%s: %s' % (command, error))
return
-
- stdout, stderr = [ x[:len(x)-1] for x in
- [ x.split('\n') for x in p.communicate()]]
- code = p.returncode
pid = p.pid
+ for line in iter(p.stdout.readline,""):
+ PRIVMSG(line)
+ log.debug('%s stdout: %s' % (pid, line))
+ p.wait()
+ elapsed = time() - start
+ code = p.returncode
+ log.info('command: %s -> %s in %d seconds' % (command, code,elapsed))
+ [log.debug('%s stderr: %s' % (pid, x)) for x in p.stderr.readlines()]
- log.info('command: %s -> %s' % (command, code))
- [log.debug('%s stdout: %s' % (pid, x)) for x in stdout]
- [log.debug('%s stderr: %s' % (pid, x)) for x in stderr]
-
- if code == 0:
- [PRIVMSG(x) for x in stdout]
- [PRIVMSG(x) for x in stderr]
- else:
+ if code != 0:
ME('mimimi')
else: