My current code is
import os
import pickle
import tempfile
# Pickle on HIGHEST_PROTOCOL breaks on Python 3.6.5
_PICKLE_PROTOCOL = 4
#CHANGED FROM 2 TO 4 TO ACCOMODATE VERSION, DONE BY USER
def _pickle_iterable(filename, iterable):
with open(filename, 'wb') as pickle_fh:
pklr = pickle.Pickler(pickle_fh, _PICKLE_PROTOCOL)
for entry in iterable:
pklr.dump(entry)
pklr.clear_memo()
def _open_pickle(filename):
return open(filename, 'rb')
def _unpickle_iterable(pickle_fh):
with pickle_fh:
unpklr = pickle.Unpickler(pickle_fh)
try:
while True:
yield unpklr.load()
except EOFError:
pass
def file_buffered_tee(iterable, n=2):
_, filename = tempfile.mkstemp()
try:
_pickle_iterable(filename, iterable)
return tuple(_unpickle_iterable(_open_pickle(filename)) for _ in range(n))
finally:
os.remove(filename)
os.remove(filename) gives the error
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\s%username%\\AppData\\Local\\Temp\\tmpaoos53ie'
I don't know how to fix it, and the GitHub repo I pulled this from is archived, and I can't open another issue request.
I'm coming back to stackoverflow, and everywhere else I've seen I cannot find an applicable answer, and while I think I understand the code, I keep hitting errors lol
Any help is appreciated! Thank you!
edit 1: forgot imports... dumb mistake
edit 2: I left out code because I thought it was un-needed. Thank you all for being patient :P
edit 3: Traceback:
line37, in file_buffered_tee:
os.remove(filename)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\%username%\\AppData\\Local\\Temp\\tmp*xxxxxxx*'
edit 4: apparently the same issue was being had here , however it does everything the answer says to do, but returns the same error... Still not answered here and still very confused. Documentation hasnt helped either