import multiprocessing


def build_pool(multiproc = True, pool_size = None):
	"""
	build_pool(multiproc = True, pool_size = None)

	if multiproc == True creates a pool using multiprocessing.Pool
	False will eventually implement a way to use the IPython cluster module instead

	pool_size is the number of workers to use.
	values are from 0 to n
	if None, a default value of 2 is set. 
	if -1, multiprocessing.cpu_count() is set.
	"""
	if not pool_size:
		pool_size = 2
	elif pool_size == -1:
		pool_size = multiprocessing.cpu_count()
	elif not isinstance(pool_size, int):
		raise TypeError
	
	if multiproc:
		# pool_size = multiprocessing.cpu_count() * 2
		pool = multiprocessing.Pool(processes=pool_size)
		return pool
	else:
		raise TypeError