This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kyle.smith
Recipients kyle.smith
Date 2022-02-27.02:58:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645930683.9.0.146416539661.issue46871@roundup.psfhosted.org>
In-reply-to
Content
The below code works on versions 3.5.2 to 3.8.10. Higher versions tested, such as 3.9.12 and 3.10.2 result in the error:
 "AttributeError: Can't pickle local object".


from multiprocessing import Lock
from multiprocessing.managers import AcquirerProxy, BaseManager, DictProxy

def get_shared_state(host, port, key):
    shared_dict = {}
    shared_lock = Lock()
    manager = BaseManager((host, port), key)
    manager.register("get_dict", lambda: shared_dict, DictProxy)
    manager.register("get_lock", lambda: shared_lock, AcquirerProxy)
    try:
        manager.get_server()
        manager.start()
    except OSError:  # Address already in use
        manager.connect()
    return manager.get_dict(), manager.get_lock()

HOST = "127.0.0.1"
PORT = 35791
KEY = b"secret"
shared_dict, shared_lock = get_shared_state(HOST, PORT, KEY)

shared_dict["number"] = 0
shared_dict["text"] = "Hello World"


This code was pulled from this article: https://stackoverflow.com/questions/57734298/how-can-i-provide-shared-state-to-my-flask-app-with-multiple-workers-without-dep/57810915#57810915


I looked around and couldn't find any open or closed bugs for this, so I'm sorry in advance if this is new expected behavior.
History
Date User Action Args
2022-02-27 02:58:03kyle.smithsetrecipients: + kyle.smith
2022-02-27 02:58:03kyle.smithsetmessageid: <1645930683.9.0.146416539661.issue46871@roundup.psfhosted.org>
2022-02-27 02:58:03kyle.smithlinkissue46871 messages
2022-02-27 02:58:03kyle.smithcreate