0

I'm experiencing a problem with the Cement framework for python (using python3 at the moment). I have a multiprocess application which uses python's Pool workers. A the end (it deos not interfere with the results) of every multiporcessing section my stdout is filled with one or more of these exceptions:

Traceback (most recent call last):
  File "/usr/lib/python3.5/multiprocessing/util.py", line 254, in _run_finalizers
    finalizer()
  File "/usr/lib/python3.5/multiprocessing/util.py", line 186, in __call__
    res = self._callback(*self._args, **self._kwargs)
  File "/usr/lib/python3.5/multiprocessing/queues.py", line 198, in _finalize_join
    thread.join()
  File "/usr/lib/python3.5/threading.py", line 1054, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.5/threading.py", line 1070, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
  File "/home/yogaub/.virtualenvs/seminar/lib/python3.5/site-packages/cement/core/foundation.py", line 123, in cement_signal_handler
    raise exc.CaughtSignal(signum, frame)
cement.core.exc.CaughtSignal: Caught signal 15

Does anyone know why this happens, and how to prevent it?

Thanks

edit: I should add that i'm logging with the multiprocess logging system of this question. I don't really know if there is any correlation.

edit2: This is the process pool creation and termination:

pool = Pool(processes=core_num)
pool.map(worker_unpacker.work, formatted_input)
pool.close()
t2 = time.time()

I've tried catching sigterm with Cement's hook system but it doesn't work. The only solution I found at the moment is to actually completely ignore signals in the cement app configuration (but it is not really a solution I like..).

Community
  • 1
  • 1
ClonedOne
  • 569
  • 4
  • 20
  • signal 15 is `SIGTERM` and happens if you send the kill signal to the process, are you running `terminate()` on the process? Can you share the part of the program where you set up the pool, run and `join` it? – hansaplast Feb 04 '17 at 11:50
  • @hansaplast Thanks, yes i understood it was sigterm. What I don't really know is who generates it and why it is not catched by Cement (even when i explicitely setup the hook). – ClonedOne Feb 04 '17 at 14:29

1 Answers1

0

This is an educated guess: The parent process kills (terminate()s) the started processes on exit. If you call pool.join() in the parent process, then the parent process waits until all sub processes are finished and will not send SIGTERM to them.

hansaplast
  • 11,007
  • 2
  • 61
  • 75
  • Thank you! The explicit call to `pool.join()` did the trick. It's strange however since python doc states that `close() Prevents any more tasks from being submitted to the pool. Once all the tasks have been completed the worker processes will exit.` Still it bothers me a little that Cement hook did not catch it. – ClonedOne Feb 04 '17 at 16:31
  • yes, when the parent process calls `close()` and a process finishes the function, then it exits normally. The issue you had was that the parent process was not waiting for so long, it already exited itself, before the workers were finished. So it tore the workers with him into death so to say. `join()` explicetly tells the parent to wait until all subprocesses have finished before exiting – hansaplast Feb 06 '17 at 21:09
  • @ClonedOne if you wish more explanation, please say so, I tried my best :-) – hansaplast Feb 06 '17 at 21:10