Last active
February 8, 2025 08:03
-
-
Save xupengzhuo/2a5416820c914b709dd1204833965cc2 to your computer and use it in GitHub Desktop.
transfer pickle using pipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ########## | |
| #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