def do_work(payload):
    with semaphore:
        return payload

def init(sem):
    global semaphore
semaphore = sem
if __name__ == '__main__':
    sem = multiprocessing.Semaphore()
with multiprocessing.Pool(initializer=init, initargs=(sem,)) as p:
    results = p.map(do_work, payloads)
Sharing a semaphore with a function using python multiprocessing