Share unpickleable object across processes
dieter
dieter at handshake.de
Fri Nov 3 02:58:10 EDT 2017
Israel Brewster <israel at ravnalaska.net> writes:
> 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?
At low (= Posix) level, socket objects are represented as
ints, representing an "open communication object".
Usually, a child process shares the parent's "open communication object"s
*AT THE TINE OF THE CHILD CREATION*. However, often, this sharing
is broken very quickly: the parent may have set up those objects
to close automatically in the child; the parent may close its
"open communication object" after the spawning of the child.
If two processes have not inherited the same "open communication object"
from a common ancestor, there is no way that they can share
the communication object.
I am quite convinced that UWSGI will
be set up to close "open communication object"s passed on to
child processes. Thus, I see little chance that your current approach
can succeed.
More information about the Python-list
mailing list