Commit bf0df5afba27437216180ff3da0c864fd443588d
1 parent
563f62ce
Exists in
master
and in
1 other branch
- remove a with statement from FileHandler
Showing
3 changed files
with
13 additions
and
8 deletions
Show diff stats
factory.py
@@ -74,6 +74,10 @@ class QFactory(object): | @@ -74,6 +74,10 @@ class QFactory(object): | ||
74 | # Given a ref returns an instance of a descendent of Question(), | 74 | # Given a ref returns an instance of a descendent of Question(), |
75 | # i.e. a question object (radio, checkbox, ...). | 75 | # i.e. a question object (radio, checkbox, ...). |
76 | # ----------------------------------------------------------------------- | 76 | # ----------------------------------------------------------------------- |
77 | + # async def generate_async(self): | ||
78 | + # loop = asyncio.get_event_loop() | ||
79 | + # return await loop.run_in_executor(None, self.generate) | ||
80 | + | ||
77 | def generate(self): | 81 | def generate(self): |
78 | logger.debug(f'Generating "{self.question["ref"]}"...') | 82 | logger.debug(f'Generating "{self.question["ref"]}"...') |
79 | # Shallow copy so that script generated questions will not replace | 83 | # Shallow copy so that script generated questions will not replace |
knowledge.py
@@ -94,7 +94,9 @@ class StudentKnowledge(object): | @@ -94,7 +94,9 @@ class StudentKnowledge(object): | ||
94 | logger.debug(f'Questions: {", ".join(questions)}') | 94 | logger.debug(f'Questions: {", ".join(questions)}') |
95 | 95 | ||
96 | # generate instances of questions | 96 | # generate instances of questions |
97 | - self.questions = [self.factory[qref].generate() for qref in questions] | 97 | + gen = lambda qref: self.factory[qref].generate() |
98 | + self.questions = [gen(qref) for qref in questions] | ||
99 | + # self.questions = [gen(qref) for qref in questions] | ||
98 | logger.debug(f'Total: {len(self.questions)} questions') | 100 | logger.debug(f'Total: {len(self.questions)} questions') |
99 | 101 | ||
100 | # get first question | 102 | # get first question |
serve.py
@@ -193,13 +193,12 @@ class FileHandler(BaseHandler): | @@ -193,13 +193,12 @@ class FileHandler(BaseHandler): | ||
193 | except Exception as e: | 193 | except Exception as e: |
194 | raise e | 194 | raise e |
195 | else: | 195 | else: |
196 | - with f: | ||
197 | - data = f.read() | ||
198 | - f.close() | ||
199 | - self.set_header("Content-Type", content_type) | ||
200 | - self.write(data) | ||
201 | - await self.flush() | ||
202 | - # self.flush() | 196 | + data = f.read() |
197 | + f.close() | ||
198 | + self.set_header("Content-Type", content_type) | ||
199 | + self.write(data) | ||
200 | + await self.flush() | ||
201 | + # self.flush() | ||
203 | 202 | ||
204 | 203 | ||
205 | # ---------------------------------------------------------------------------- | 204 | # ---------------------------------------------------------------------------- |