2

This 2.7 Python script on MacOSx does not close Python processes. After script runs there are 8 dormant such processes. How can I close them at end of script? *.terminate didn't work.

import multiprocessing
newlist = range(1,30)

ULs = [row for row in newlist]
print ULs

def ULtask(ul):
    print 1234

def start_process(): 
  print 'Start', multiprocessing.current_process().name

p_size      = multiprocessing.cpu_count() * 2
pool        = multiprocessing.Pool(processes=p_size, initializer=start_process, maxtasksperchild=400,)
pool_outputs= pool.map(ULtask, ULs)
pool.close() # no more tasks
pool.join()  # wrap up current tasks
# pool.terminate()

print 'Pool    :', pool_outputs
del pool
print "Finished  UL"
tshepang
  • 12,111
  • 21
  • 91
  • 136
Merlin
  • 24,552
  • 41
  • 131
  • 206

1 Answers1

0

Try the last tip on this thread (python multiprocessing pool terminate). It looks like it puts terminate in between the close & join calls.

I tried a simple pool on my machine (mac osx), and the pool processes terminated fine with just the close & join calls, but terminate didn't hurt anything. It looks like join will kill processes with the pool being in either close or terminate (you can see this from the error message if you try to join without a close or terminate before it.)

Community
  • 1
  • 1
anonygrits
  • 1,459
  • 2
  • 14
  • 19