build_a_blog: multiprocessing
This commit is contained in:
parent
23042c2d35
commit
d2b810441d
2 changed files with 95 additions and 4 deletions
11
main.py
11
main.py
|
@ -1,9 +1,11 @@
|
|||
import os
|
||||
import re
|
||||
import glob
|
||||
import html
|
||||
import email
|
||||
import logging
|
||||
import datetime
|
||||
from multiprocessing import Pool, TimeoutError
|
||||
from string import Template
|
||||
|
||||
import markdown
|
||||
|
@ -13,6 +15,7 @@ destpath_re = re.compile(r'\.md$')
|
|||
logging.basicConfig(encoding='utf-8', level=logging.INFO)
|
||||
|
||||
md = markdown.Markdown(extensions=['extra', 'meta', TocExtension(anchorlink=True)])
|
||||
cpu_count = os.cpu_count()
|
||||
|
||||
def convert(text):
|
||||
md.reset()
|
||||
|
@ -52,11 +55,11 @@ def render_posts():
|
|||
files = glob.glob('posts/*.md')
|
||||
logging.info('found post files %s', files)
|
||||
posts = []
|
||||
for fname in files:
|
||||
p = render_post(fname)
|
||||
posts.append(p)
|
||||
logging.info('rendered post: %s', p)
|
||||
logging.info('starting render posts with cpu_count: %d', cpu_count)
|
||||
with Pool(processes=cpu_count) as pool:
|
||||
posts = pool.map(render_post, files)
|
||||
|
||||
logging.info("render_posts result: %s", res)
|
||||
return posts
|
||||
|
||||
def posts_list_html(posts):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue