Share unpickleable object across processes

Chris Angelico rosuav at gmail.com
Thu Nov 2 16:36:48 EDT 2017


On Fri, Nov 3, 2017 at 7:35 AM, Israel Brewster <israel at ravnalaska.net> wrote:
> On Nov 2, 2017, at 12:30 PM, Chris Angelico <rosuav at gmail.com> wrote:
>>
>> On Fri, Nov 3, 2017 at 5:54 AM, Israel Brewster <israel at ravnalaska.net> wrote:
>>> I have a Flask/UWSGI web app that serves up web socket connections. When a web socket connection is created, I want to store a reference to said web socket so I can do things like write messages to every connected socket/disconnect various sockets/etc. UWSGI, however, launches multiple child processes which handle incoming connections, so the data structure that stores the socket connections needs to be shared across all said processes. How can I do this?
>>>
>>
>> You're basically going to need to have a single process that manages
>> all the socket connections. Do you actually NEED multiple processes to
>> do your work? If you can do it with multiple threads in a single
>> process, you'll be able to share your socket info easily. Otherwise,
>> you could have one process dedicated to managing the websockets, and
>> all the others message that process saying "please send this to all
>> processes".
>
> Ok, that makes sense, but again: it's UWSGI that creates the processes, not me. I'm not creating *any* processes or threads. Aside from telling UWSGI to only use a single worker, I have no control over what happens where. But maybe that's what I need to do?
>

That's exactly what I mean, yeah. UWSGI should be able to be told to
use threads instead of processes. I don't know it in detail, but a
cursory look at the docos suggests that it's happy to use either (or
even both).

ChrisA



More information about the Python-list mailing list