diff --git a/IPython/kernel/zmq/session.py b/IPython/kernel/zmq/session.py index 91da4b3..3b00aaa 100644 --- a/IPython/kernel/zmq/session.py +++ b/IPython/kernel/zmq/session.py @@ -318,6 +318,9 @@ class Session(Configurable): with open(new, 'rb') as f: self.key = f.read().strip() + # for protecting against sends from forks + pid = Integer() + # serialization traits: pack = Any(default_packer) # the actual packer function @@ -341,6 +344,7 @@ class Session(Configurable): Containers larger than this are pickled outright. """ ) + def __init__(self, **kwargs): """create a Session object @@ -382,6 +386,7 @@ class Session(Configurable): self.none = self.pack({}) # ensure self._session_default() if necessary, so bsession is defined: self.session + self.pid = os.getpid() @property def msg_id(self): @@ -568,7 +573,10 @@ class Session(Configurable): else: msg = self.msg(msg_or_type, content=content, parent=parent, header=header, metadata=metadata) - + if not os.getpid() == self.pid: + io.rprint("WARNING: attempted to send message from fork") + io.rprint(msg) + return buffers = [] if buffers is None else buffers to_send = self.serialize(msg, ident) to_send.extend(buffers)