summaryrefslogtreecommitdiffstats
path: root/captcha
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-07-29 12:57:06 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-07-29 12:57:06 +0200
commit2c7e40bd77515065dc0bcdba3b724b9d071ab31c (patch)
tree0d61c26bdabeca521f255d0de43a14f8fe9156a5 /captcha
parentfixed netload.in (diff)
downloadpyload-2c7e40bd77515065dc0bcdba3b724b9d071ab31c.tar.xz
captcha reading timeout, to avoid hang up
Diffstat (limited to 'captcha')
-rw-r--r--captcha/captcha.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/captcha/captcha.py b/captcha/captcha.py
index 8f0b828d8..6d4cd86e8 100644
--- a/captcha/captcha.py
+++ b/captcha/captcha.py
@@ -1,3 +1,4 @@
+import thread
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
@@ -22,6 +23,29 @@ import tempfile
import Image
import ImageOps
+import threading
+
+class RunThread(threading.Thread):
+ def __init__(self):
+ threading.Thread.__init__(self)
+
+ def e(self, command, inputdata=None):
+ """execute command """
+ self.command = command
+ self.inputdata = inputdata
+ self.result = ""
+ self.start()
+ self.join(10)
+ return self.result
+
+ def run(self):
+ """Run a command and return standard output"""
+ pipe = subprocess.PIPE
+ popen = subprocess.Popen(self.command, stdout=pipe, stderr=pipe)
+ outputdata, errdata = popen.communicate(self.inputdata)
+ assert (popen.returncode == 0), \
+ "Error running: %s\n\n%s" % (self.command, errdata)
+ self.result = outputdata
class OCR(object):
def __init__(self):
@@ -41,12 +65,18 @@ class OCR(object):
def run(self, command, inputdata=None):
"""Run a command and return standard output"""
- pipe = subprocess.PIPE
- popen = subprocess.Popen(command, stdout=pipe, stderr=pipe)
- outputdata, errdata = popen.communicate(inputdata)
- assert (popen.returncode == 0), \
- "Error running: %s\n\n%s" % (command, errdata)
- return outputdata
+# OLD METHOD
+# pipe = subprocess.PIPE
+# popen = subprocess.Popen(command, stdout=pipe, stderr=pipe)
+# outputdata, errdata = popen.communicate(inputdata)
+# assert (popen.returncode == 0), \
+# "Error running: %s\n\n%s" % (command, errdata)
+# return outputdata
+
+ thread = RunThread()
+ result = thread.e(command, inputdata)
+ print result
+ return result
def run_gocr(self):
tmp = tempfile.NamedTemporaryFile(suffix=".jpg")