multiprocessing.Pool – PicklingError: Can’t pickle : attribute lookup thread.lock failed

multiprocessing passes tasks (which include check_one and data) to the worker processes through a mp.SimpleQueue. Unlike Queue.Queues, everything put in the mp.SimpleQueue must be pickable. Queue.Queues are not pickable: import multiprocessing as mp import Queue def foo(queue): pass pool=mp.Pool() q=Queue.Queue() pool.map(foo,(q,)) yields this exception: UnpickleableError: Cannot pickle <type ‘thread.lock’> objects Your data includes packages, which … Read more

Is it really my job to clean up ThreadLocal resources when classes have been exposed to a thread pool?

Sigh, this is old news Well, a bit late to the party on this one. In October 2007, Josh Bloch (co-author of java.lang.ThreadLocal along with Doug Lea) wrote: “The use of thread pools demands extreme care. Sloppy use of thread pools in combination with sloppy use of thread locals can cause unintended object retention, as … Read more

How can I shutdown Spring task executor/scheduler pools before all other beans in the web app are destroyed?

Two ways: Have a bean implement ApplicationListener<ContextClosedEvent>. onApplicationEvent() will get called before the context and all the beans are destroyed. Have a bean implement Lifecycle or SmartLifecycle. stop() will get called before the context and all the beans are destroyed. Either way you can shut down the task stuff before the bean destroying mechanism takes … Read more

What determines the number of threads a Java ForkJoinPool creates?

There’re related questions on stackoverflow: ForkJoinPool stalls during invokeAll/join ForkJoinPool seems to waste a thread I made a runnable stripped down version of what is happening (jvm arguments i used: -Xms256m -Xmx1024m -Xss8m): import java.util.ArrayList; import java.util.List; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.RecursiveAction; import java.util.concurrent.RecursiveTask; import java.util.concurrent.TimeUnit; public class Test1 { private static ForkJoinPool pool = new … Read more