For a flood warning system, my Raspberry Pi rings the bells in near-real-time but uses a NAS drive as a postbox to output data files to a PC for slower-time graphing and reporting, and to receive various input data files back.  Python on the Pi takes precisely 10 seconds to establish that the NAS drive right next to it is not currently available.  I need that to happen in less than a second for each access attempt, otherwise the delays add up and the Pi fails to refresh the hardware watchdog in time.  (The Pi performs tasks on a fixed cycle:  every second, every 15 seconds (watchdog), every 75 seconds and every 10 minutes.)  All disc access attempts are preceded by tests with try-except.  But try-except doesn't help, as tests like os.path.exists() or with open() both take 10 seconds before raising the exception, even when the NAS drive is powered down.  It's as though there's a 10-second timeout way down in the comms protocol rather than up in the software.
Is there a way of telling try-except not to be so patient?  If not, how can I get a more immediate indicator of whether the NAS drive is going to hold up the Pi at the next read/write, so that the Pi can give up and wait till the next cycle?  I've done all the file queueing for that, but it's wasted if every check takes 10 seconds.
Taking on MQTT at this stage would be a big change to this nearly-finished project.  But your suggestion of decoupling the near-real-time Python from the NAS drive by using a second script is I think the way to go.  If the Python disc interface commands wait 10 seconds for an answer, I can't help that.  But I can stop it holding up the time-critical Python functions by keeping all time-critical file accesses local in Pi memory, and replicating whole files in both directions between the Pi and the NAS drive whenever they change.  In fact I already have the opportunistic replicator code in Python - I just need to move it out of the main time-critical script into a separate script that will replicate the files.  And the replicator Python script will do any waiting, rather than the time-critical Python script.  The Pi scheduler will decouple the two scripts for me.  Thanks for your help - I was beginning to despair!
How can Python test the availability of a NAS drive really quickly?