husonet | Tarih: 30.01.2014
Parallelisim proses bazlı thread işlemi
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib2
from multiprocessing.dummy import Pool as ThreadPool
urls = [
'http://www.pythontr.com',
'http://www.habermonitor.com/tr/rss',
'/makaleler.py',
'http://www.python.org/download/',
'http://www.python.org/getit/',
'http://www.python.org/community/',
'https://wiki.python.org/moin/',
'http://planet.python.org/',
'https://wiki.python.org/moin/LocalUserGroups',
'http://www.python.org/psf/',
'http://docs.python.org/devguide/',
'http://www.python.org/community/awards/'
# etc..
]
# islemci sayisi 4 ise
pool = ThreadPool(4)
# Thrads pool ile butun url leri acalim
# ve donuslerini alalim
results = pool.map(urllib2.urlopen, urls)
# islemleri bitirelim kapatalim
pool.close()
pool.join()
Kaynak : https://medium.com/building-things-on-the-internet/40e9b2b36148