Skip to content

Instantly share code, notes, and snippets.

@zed
Last active July 30, 2022 00:23
Show Gist options
  • Select an option

  • Save zed/9334570 to your computer and use it in GitHub Desktop.

Select an option

Save zed/9334570 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Try to cause MemoryError by sending large data via multiprocessing.Pipe.
Context: http://stackoverflow.com/q/22150703
"""
from multiprocessing import Process, Pipe
def send_big_data(conn):
data = b"a" * (1 << 30) # 1GB
conn.send(data)
conn.close() # eof
if __name__=="__main__":
parent_conn, child_conn = Pipe()
child = Process(target=send_big_data, args=(child_conn,))
child.start()
child_conn.close() # child must be the only with it opened
print(len(parent_conn.recv()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment