Skip to content

Instantly share code, notes, and snippets.

@xupengzhuo
Last active February 8, 2025 08:03
Show Gist options
  • Select an option

  • Save xupengzhuo/2a5416820c914b709dd1204833965cc2 to your computer and use it in GitHub Desktop.

Select an option

Save xupengzhuo/2a5416820c914b709dd1204833965cc2 to your computer and use it in GitHub Desktop.
transfer pickle using pipe
##########
#parent.py
##########
import subprocess
import pickle
process = subprocess.Popen(
['python', 'child.py'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
bufsize=0
)
pickle.dump({'ffff'}, process.stdin)
output = pickle.load(process.stdout)
print(output)
##########
#child.py
##########
import sys
import pickle
input = pickle.load(sys.stdin.buffer)
input.add('cccccc')
pickle.dump(input, sys.stdout.buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment