recover pickled data: pickle data was truncated

Barry Scott barry at barrys-emacs.org
Sun Dec 26 11:43:53 EST 2021



> On 26 Dec 2021, at 13:44, Marco Sulla <Marco.Sulla.Python at gmail.com> wrote:
> 
> Use a semaphore.
> 
> On Sun, 26 Dec 2021 at 03:30, iMath <redstone-cold at 163.com> wrote:
>> 
>> Normally, the shelve data should be read and write by only one process at a time, but unfortunately it was simultaneously read and write by two processes, thus corrupted it. Is there any way to recover all data in it ? Currently I just get "pickle data was truncated" exception after reading a portion of the data?

You have lost the data in that case.

You will need to do what Marco suggests and lock access to the file.
How you do that depends your OS. If is unix OS then its likely you
will want to use fcntl.flock().

Barry



More information about the Python-list mailing list