python - Processes in multiprocessing.Pool not reporting runtime errors -


I have a pool of processes in Python that has been used from multiprocessing import pool . I run various tasks to pass those people, calling the Pool.apply_async function. If I start one of those errors (i.e.: a line of code, such as 5/0 ), expected command line report ZeroVision Aire: Zero by integer division or modules Never shows, and the program never ends, even if I present a callback function in the call to "Code.Apple_async , I never called the callback function. Goes, if the function is done To Anvit is an error on that.

How can I get those errors in the errors of the pool report and if something goes wrong, then what can be terminated?

In order for you to be raised in the parent, the actual apply_async (Or map_async ), try the returned results.

  def func (): Exception ("we failed") ... results = pool.app_a_sync (funk, args = (arg)) time.sleep (2) result.get ( ) # Exception is only picked here.   

You can execute any callback only function if the function returns successfully. If it raises an exception, it is abandoned

In Python 3.2+, the keyword argument was introduced, which allows you to pass a callback that is executed if the worker is in a Exception is picked up, but you can not do that in Python 2.x What you can do is to wrap your worker's work in adopting any exception, instead of lifting it into return worker in except try / block. . :

  def func (): try: Exception exception ("we fail") Exception e: Return e   

Then you will get a normal callback The function that checks to see if the exception was returned:

  def callback (result): ifinstance (result, exception): # Also have to clean and exit: # function was successful    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -