|
|
@@ -13,6 +13,8 @@ from config import config
|
|
|
|
|
|
class Markov:
|
|
|
def __init__(self):
|
|
|
+ self.rebuilding = False
|
|
|
+
|
|
|
self.counter = 0
|
|
|
|
|
|
self.corpus = []
|
|
|
@@ -60,9 +62,17 @@ class Markov:
|
|
|
return text.strip()
|
|
|
|
|
|
def _rebuild(self):
|
|
|
- self.chain = markovify.Chain(self.corpus, config.MARKOV_STATE_SIZE).compile()
|
|
|
+ try:
|
|
|
+ self.chain = markovify.Chain(self.corpus, config.MARKOV_STATE_SIZE).compile()
|
|
|
+ finally:
|
|
|
+ self.rebuilding = False
|
|
|
|
|
|
def rebuild(self):
|
|
|
+ if self.rebuilding:
|
|
|
+ return
|
|
|
+
|
|
|
+ self.rebuilding = True
|
|
|
+
|
|
|
self.counter = 0
|
|
|
|
|
|
t = threading.Thread(target=self._rebuild)
|