Re: [Repoze-dev] Using the multiprocessing module

2010-04-12 Thread Shane Hathaway
On 04/10/2010 07:00 AM, Andreas Jung wrote:
 is it save to use the 'multiprocessing' module inside a BFG app?
 In particular I need to maintain a multiprocessing.Pool() instance...
 this is working at the first glance however the BFG app won't shutdown
 in a clean way when stopped through a keyboard interrupt. The apps
 hangs usually inside the following code:

In general, it is not safe to use multiprocessing except at the top 
level of any application.  I would set up the multiple processes before 
creating the WSGI stack or importing anything from any web framework.

Shane
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] Using the multiprocessing module

2010-04-12 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Shane Hathaway wrote:
 On 04/10/2010 07:00 AM, Andreas Jung wrote:
 is it save to use the 'multiprocessing' module inside a BFG app?
 In particular I need to maintain a multiprocessing.Pool() instance...
 this is working at the first glance however the BFG app won't shutdown
 in a clean way when stopped through a keyboard interrupt. The apps
 hangs usually inside the following code:
 
 In general, it is not safe to use multiprocessing except at the top
 level of any application.  I would set up the multiple processes before
 creating the WSGI stack or importing anything from any web framework.
 

I am using the multiprocessing in several Zope 2 apps on the product
layer without issues. So this is working usually. In this case I tried
using multiprocessing at a much higher level..

Andreas
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvD52QACgkQCJIWIbr9KYw/YgCg2run+tsoXYvlsNQJMBDxCr3q
9sIAoOlqIHyfcPxSs5AZX88sNWILwVPN
=qO39
-END PGP SIGNATURE-
attachment: lists.vcf___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] Using the multiprocessing module

2010-04-10 Thread Chris McDonough
On 4/10/10 9:00 AM, Andreas Jung wrote:
 is it save to use the 'multiprocessing' module inside a BFG app?

I don't know think it is any less safe to use it in BFG than it would be in any 
other app.

Multiprocessing does some weird stuff at startup time in its utils module. 
For instance:

def _exit_function():
 global _exiting

 info('process shutting down')
 debug('running all atexit finalizers with priority = 0')
 _run_finalizers(0)

 for p in active_children():
 if p._daemonic:
 info('calling terminate() for daemon %s', p.name)
 p._popen.terminate()

 for p in active_children():
 info('calling join() for process %s', p.name)
 p.join()

 debug('running the remaining atexit finalizers')
 _run_finalizers()

atexit.register(_exit_function)

Library code that registers an atexit hook or mutates module global state for 
purposes other than defining classes, functions, or variables as the result of 
an import is lame, lame, lame, lame.  I'm sure this is the reason you're 
getting this traceback but I don't know how to avoid it.

 In particular I need to maintain a multiprocessing.Pool() instance...
 this is working at the first glance however the BFG app won't shutdown
 in a clean way when stopped through a keyboard interrupt. The apps
 hangs usually inside the following code:

File /opt/python-2.6.4/lib/python2.6/atexit.py, line 24, in
 _run_exitfuncs
  func(*targs, **kargs)
File /opt/python-2.6.4/lib/python2.6/multiprocessing/util.py, line
 260, in _exit_function
  _run_finalizers(0)
File /opt/python-2.6.4/lib/python2.6/multiprocessing/util.py, line
 235, in _run_finalizers
  finalizer()
File /opt/python-2.6.4/lib/python2.6/multiprocessing/util.py, line
 174, in __call__
  res = self._callback(*self._args, **self._kwargs)
File /opt/python-2.6.4/lib/python2.6/multiprocessing/pool.py, line
 363, in _terminate_pool
  cls._help_stuff_finish(inqueue, task_handler, len(pool))
File /opt/python-2.6.4/lib/python2.6/multiprocessing/pool.py, line
 348, in _help_stuff_finish
  inqueue._rlock.acquire()

 There is a Pool.terminate() method for closing the pool manually however
 I don't know exactly where to trigger the code.

I think you probably need to ask on the Python-users newsgroup or ask the 
author of multiprocessing.

- C

___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev