summaryrefslogtreecommitdiff
path: root/lulua/text.py
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-10-02 16:29:10 +0200
committerLars-Dominik Braun <lars@6xq.net>2019-10-03 09:14:03 +0200
commit41a60920e413a513801ba186de86e2a7fd7ef9c3 (patch)
tree3f57d652060e535534499305b75d336e61d3cbb1 /lulua/text.py
parentdf83b0ccebd5371c286cddf44b1afb2adcc0072f (diff)
downloadlulua-41a60920e413a513801ba186de86e2a7fd7ef9c3.tar.gz
lulua-41a60920e413a513801ba186de86e2a7fd7ef9c3.tar.bz2
lulua-41a60920e413a513801ba186de86e2a7fd7ef9c3.zip
text: Fail if workers die
Diffstat (limited to 'lulua/text.py')
-rw-r--r--lulua/text.py68
1 files changed, 39 insertions, 29 deletions
diff --git a/lulua/text.py b/lulua/text.py
index f0a1b3b..98c7824 100644
--- a/lulua/text.py
+++ b/lulua/text.py
@@ -179,39 +179,44 @@ charMap = {
}
def writeWorker (args, inq, outq):
- keyboard = defaultKeyboards['ibmpc105']
- layout = defaultLayouts['null'].specialize (keyboard)
- w = Writer (layout)
- combined = dict ((cls.name, cls(w)) for cls in allStats)
-
- while True:
- keyboard = defaultKeyboards[args.keyboard]
- layout = defaultLayouts[args.layout].specialize (keyboard)
+ try:
+ keyboard = defaultKeyboards['ibmpc105']
+ layout = defaultLayouts['null'].specialize (keyboard)
w = Writer (layout)
+ combined = dict ((cls.name, cls(w)) for cls in allStats)
+
+ while True:
+ keyboard = defaultKeyboards[args.keyboard]
+ layout = defaultLayouts[args.layout].specialize (keyboard)
+ w = Writer (layout)
+
+ item = inq.get ()
+ if item is None:
+ break
+
+ # extract
+ text = sources[args.source] (item)
+ text = ''.join (map (lambda x: charMap.get (x, x), text))
+ # XXX sanity checks, disable
+ for c in charMap.keys ():
+ if c in text:
+ #print (c, 'is in text', file=sys.stderr)
+ assert False, c
+
+ # stats
+ stats = [cls(w) for cls in allStats]
+ for match, event in w.type (StringIO (text)):
+ for s in stats:
+ s.process (event)
- item = inq.get ()
- if item is None:
- break
-
- # extract
- text = sources[args.source] (item)
- text = ''.join (map (lambda x: charMap.get (x, x), text))
- # XXX sanity checks, disable
- for c in charMap.keys ():
- if c in text:
- #print (c, 'is in text', file=sys.stderr)
- assert False, c
-
- # stats
- stats = [cls(w) for cls in allStats]
- for match, event in w.type (StringIO (text)):
for s in stats:
- s.process (event)
-
- for s in stats:
- combined[s.name].update (s)
+ combined[s.name].update (s)
- outq.put (combined)
+ outq.put (combined)
+ except Exception as e:
+ # async exceptions
+ outq.put (None)
+ raise
def write ():
""" Extract corpus source file, convert to plain text, map chars and create stats """
@@ -244,6 +249,10 @@ def write ():
for l in sys.stdin:
inq.put (l)
bar.update (n=1)
+
+ # something is wrong
+ if not outq.empty ():
+ return 1
except KeyboardInterrupt:
pass
@@ -257,4 +266,5 @@ def write ():
for w in workers:
w.join ()
+ return 0