Created
June 15, 2012 19:03
-
-
Save eclarke/2938199 to your computer and use it in GitHub Desktop.
Spawning processes in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import multiprocessing | |
store_results_sql = """ some sql code here """ | |
select_results_sql = """ some other sql code here """ | |
def find_enriched(**kwargs): | |
# do some heavy computation task here | |
results = enrichment_analysis(**kwargs) | |
# sqlite is not ideal for parallel processing, but with a timeout it should be fine | |
with sqlite3.connect("results.db", timeout=30) as conn: | |
conn.execute(store_results_sql, results) | |
conn.commit | |
blocks = [chunk_1, chunk_2, ...] | |
jobs = [] | |
for block in blocks: | |
p = multiprocessing.Process(target=find_enriched, | |
args=(dataset, platform, factor, subset, | |
block, year, uniprot2entrez_map)) | |
jobs.append(p) | |
p.start() | |
# wait for them all to finish | |
[p.join() for p in jobs] | |
with sqlite3.connect("results.db", timeout=30) as conn: | |
for result in conn.execute(select_results_sql): | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment