Multiprocessing relies on pickling to communicate objects between processes. The pyodbc connection and cursor objects can not be pickled.

>>> cPickle.dumps(aCursor)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.5/copy_reg.py", line 69, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle Cursor objects
>>> cPickle.dumps(dbHandle)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.5/copy_reg.py", line 69, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle Connection objects

"It puts items in the work_queue", what items? Is it possible the cursor object is getting passed as well?

Answer from Mark on Stack Overflow
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 446
TypeError: can't pickle pyodbc.Connection objects · Issue #446 · mkleehammer/pyodbc
August 22, 2018 - Python: 3.6(64 bit) pyodbc: 4.0.23 OS: windows server 2012 R2 DB: SQL server 2012 R2 driver: {SQL Server} I'm Facing issue saying that "TypeError: can't pickle pyodbc.Connection objects" Multithreading using pool=3 Traceback (most recent...
Author: mkleehammer
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 1398
cannot pickle 'pyodbc.Connection' error when using APScheduler with a database connection · Issue #1398 · mkleehammer/pyodbc
January 8, 2025 - The function fails with the following error: TypeError: cannot pickle 'pyodbc.Connection' object The issue arises because pyodbc.Connection objects cannot be serialized (pickled), and APScheduler with ProcessPoolExecutor tries to pickle arguments passed to the scheduled job function.
Author: mkleehammer
🌐
Stack Overflow
stackoverflow.com › questions › 59614242 › cannot-pickle-connection-object
python - Cannot pickle connection object - Stack Overflow
I am using following code to connect to the SQL Server and return the connection in order to be able to use in other function. However, I am getting an error of can't pickle pyodbc.Connection objec...
🌐
GitHub
github.com › mkleehammer › pyodbc › wiki › Connection
Connection · mkleehammer/pyodbc Wiki · GitHub
Once a connection to the database ... (specifically a single HDBC). Connections also manage database transactions. Connection objects cannot be pickled....
Author: mkleehammer
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-56522
cannot pickle 'sqlite3.Connection' object in pyCharm
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 45942143 › python-multiprocess-picklingerror-cant-pickle
multiprocessing - Python multiprocess - PicklingError: Cant pickle - Stack Overflow
line 53, in run_queries dfs_queries = p.map(run_query, queries) File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get() File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get raise self._value PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed · I have looked into this question which suggests that the pyodbc connection and cursor objects can not be pickled.
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 508
Multiprocessing, cursor.fetcall and 'TypeError(“can't pickle pyodbc.Row objects”,)' · Issue #508 · mkleehammer/pyodbc
January 16, 2019 - Using logger i can see that it returns all the data but it shows: MaybeEncodingError: Error sending result: '[[(Decimal('14674'), u'\u0391', u'\u03a7\u039b', 1, 101, 4256815.0, 464554.0, u'117275892689', Decimal('187143225'), Decimal('1001002488331661'), u'1.31670565', u'\u0395\u039b\u0395\u03a5\u0398. \u0392\u0395\u039d\u0399\u0396\u0395\u039b\u039f\u03a5 46'),......]]'. Reason: 'TypeError("can't pickle pyodbc.Row objects",)'
Author: mkleehammer
🌐
Google Code
code.google.com › archive › p › pyodbc › wikis › Objects.wiki
Google Code Archive - Long-term storage for Google Code Project Hosting.
Archive · Skip to content · The Google Code Archive requires JavaScript to be enabled in your browser · Google · About Google · Privacy · Terms
🌐
Stack Overflow
stackoverflow.com › questions › 71523537 › airflow-typeerror-cannot-pickle-pyodbc-cursor-object
python 3.x - airflow TypeError: cannot pickle 'pyodbc.Cursor' object - Stack Overflow
{python.py:175} INFO - Done. Returned value was: [2022-03-18, 17:56:17 UTC] {taskinstance.py:1700} ERROR - Task failed with exception Traceback (most ...
🌐
Jod
jod.al › 2011 › 03 › 06 › pickling-multiprocessing-connection-objects
Pickling multiprocessing Connection objects - jod.al
March 6, 2011 - """ def __init__(self, connection): self._connection = connection def __reduce__(self): (conn_func, conn_args) = multiprocessing.reduction.reduce_connection( self._connection) wrapper_func = _ConnectionWrapperRebuilder(conn_func) return (wrapper_func, conn_args) def __getattr__(self, name): return getattr(self._connection, name) class _ConnectionWrapperRebuilder(object): """ Internal class used by :class:`ConnectionWrapper` to rewrap :class:`multiprocessing.Connection` objects when they are depickled. A function defined inside :meth:`ConnectionWrapper.__reduce__` which takes :attr:`conn_func` from its scope cannot be used, as functions must be defined at the module's top level to be picklable.
🌐
Geek Python
geekpython.in › pickle-module-in-python
Pickle Python Object Using the pickle Module
March 1, 2024 - However, not all types of objects are picklable. Certain types of objects, for example, file handles, sockets, database connections, and custom classes that lack necessary methods (such as __getstate__ and __setstate__), may not be picklable.
🌐
Brian simulator
brian.discourse.group › support
TypeError: cannot pickle 'sqlite3.Connection' object when running Ray Tune with Jupyter notebook script - Support - Brian simulator
November 18, 2022 - Description of problem I got an “TypeError: cannot pickle ‘sqlite3.Connection’ object” error when running the attached Ray Tune code. The code need to import a notebook script called ttt.ipynb. Such an error won’t show…
🌐
Medium
medium.com › devopss-hole › python-multiprocessing-pickle-issue-e2d35ccf96a9
Python “multiprocessing” “Can't pickle…” - TedChen
May 26, 2022 - The ‘pickle’ issue in ‘multiprocessing’ is because of passing objects as arguments between process.
🌐
GitHub
github.com › mkleehammer › pyodbc › issues › 649
TypeError when trying to unpickle results with equal column names · Issue #649 · mkleehammer/pyodbc
November 21, 2019 - When trying to unpickle a result ... cannot create 'pyodbc.Row' instances · I noticed that at work where we have a MS SQL Server, but it is possible to reproduce the error with sqlite. import sqlite3 import pickle import pyodbc # create a database conn = sqlite3.connect("db.db") c ...
Author: mkleehammer