5

I have encountered an issue with the Python multiprocessing library when using PySQLPool. It results in me getting the following exception: 'TypeError: 'NoneType' object is not callable'.

I create a Pool using multiprocessing, and call Pool.map on a dummy function. In the arguments to map I include a connection from PySQLPool. I have included the minimum code I could reproduce the bug with below:

from config import *
import PySQLPool
import multiprocessing as mp
def a(b):
    return b
PySQLPool.getNewPool().maxActiveConnections = 5
connection = PySQLPool.getNewConnection(user=USER,
                    passwd=PASSWORD,
                    host='localhost',
                    db=DATABASE,
                    use_unicode=True,
                    charset='utf8',
                    commitOnEnd=False)
pool = mp.Pool(processes=8)
args = [(connection)]
result_list = pool.map(a, args, 8)
pool.close()
pool.join()

It results in the following error:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/root/.pyenv/versions/2.7.6/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/root/.pyenv/versions/2.7.6/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/root/.pyenv/versions/2.7.6/lib/python2.7/multiprocessing/pool.py", line 342, in _handle_tasks
    put(task)
TypeError: 'NoneType' object is not callable

I have the following installed with pip

(venv)root@Ubuntu-1204-precise-64-minimal:/usr/share/python-multiproc/src# pip list
MySQL-python (1.2.5)
pip (6.0.8)
PySQLPool (0.3.8)
setuptools (12.0.5)

I have tested it on Ubuntu 12.04 with Python version 2.7.3, 2.7.6, and 2.7.9. Also tested on Windows 8 with Python 2.7.9. Furthermore I have tried with both PySQLPool 0.3.8 and 0.4.

What is the cause of this and how can I debug it?

1
  • Not really a solution to the above problem, but I have used MySQLdb instead of PySQLdb and am now relying on the number of processes to limit the number of connections created. I think it's suboptimal, but it seems to work. Commented Mar 10, 2015 at 13:44

1 Answer 1

1

This obscure error can come from corrupted arguments passed to the called function. This can happen with complex objects due to pickling/unpickling logic.

If possible try reworking your code to pass the absolute minimum number of args to your function. This may mean to re-create some objects inside each process.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.