Python SDK: how to properly manage access token?

Python SDK: how to properly manage access token?

Hi, I've a python script that updates quite some records in my CRM. The script takes time to complete so it happens that the access token expires in the middle of the script and this might cause an error (sometimes the refresh happens automatically, managed by the SDK, usually for reading, but sometimes not, especially when writing) so the script terminates (gracefully, every operation is in a try block). The question is: how to properly handle the access token to avoid such error? Actually the SDK is supposed to take care of it but it looks like it does not. 
Regards,
Andrea