2016-07-07, 21:52
Based on an example from stackexchange I have created a small example on parallel TeX compilation.
# -*- coding: utf-8 -*-
"""
Created on 2016-07-06
Uwe Ziegenhagen
based on http://stackoverflow.com/questions/16181121/python-very-simple-multithreading-parallel-url-fetching-without-queue
"""
from multiprocessing.pool import ThreadPool
from time import time as timer
import os
files = ['test-01.tex','test-02.tex','test-03.tex','test-04.tex','test-05.tex',
'test-06.tex','test-07.tex','test-08.tex','test-09.tex','test-10.tex']
def compile_file(cfile):
try:
result = os.system('pdflatex -interaction=batchmode ' + cfile)
return cfile, None
except Exception as e:
return cfile, e
start = timer()
results = ThreadPool(8).imap_unordered(compile_file, files)
for cfile, error in results:
if error is None:
print("%r compiled in %ss" % (cfile, timer() - start))
else:
print("Error compiling %r: %s" % (cfile, error))
print("Elapsed Time: %s" % (timer() - start,))
print('Gesamtzeit',timer() - start) |
# -*- coding: utf-8 -*-
"""
Created on 2016-07-06
Uwe Ziegenhagen
based on http://stackoverflow.com/questions/16181121/python-very-simple-multithreading-parallel-url-fetching-without-queue
"""
from multiprocessing.pool import ThreadPool
from time import time as timer
import os
files = ['test-01.tex','test-02.tex','test-03.tex','test-04.tex','test-05.tex',
'test-06.tex','test-07.tex','test-08.tex','test-09.tex','test-10.tex']
def compile_file(cfile):
try:
result = os.system('pdflatex -interaction=batchmode ' + cfile)
return cfile, None
except Exception as e:
return cfile, e
start = timer()
results = ThreadPool(8).imap_unordered(compile_file, files)
for cfile, error in results:
if error is None:
print("%r compiled in %ss" % (cfile, timer() - start))
else:
print("Error compiling %r: %s" % (cfile, error))
print("Elapsed Time: %s" % (timer() - start,))
print('Gesamtzeit',timer() - start)
Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined.
Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.
More Posts - Website