is os.sync a non-blocking?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
bradstew
Posts: 41
Joined: Thu Nov 29, 2018 9:29 pm

is os.sync a non-blocking?

Post by bradstew » Tue Dec 07, 2021 6:58 pm

Hi,
Using MPy 1.17, stm32F405

I have a program that will do some os tasks on the flash memory such as renaming and moving files and directories. After this, it issues:
os.sync()
pyb.hard_reset()

In some rare cases, it won't reboot as the file system became corrupted.

So is it possible that os.sync() is still in running when the hard reset occurs?
In other wordsk, is os.sync() a non-blocking task?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: is os.sync a non-blocking?

Post by pythoncoder » Wed Dec 08, 2021 9:51 am

Almost all corruption issues are due to this problem.
Peter Hinch
Index to my micropython libraries.

bradstew
Posts: 41
Joined: Thu Nov 29, 2018 9:29 pm

Re: is os.sync a non-blocking?

Post by bradstew » Wed Dec 08, 2021 4:33 pm

So a possible solution is to insert some delay (more than 10ms) after os.sync()?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: is os.sync a non-blocking?

Post by pythoncoder » Thu Dec 09, 2021 9:44 am

If the problem is as per my FAQ quoted above, the only solution is to disable MSC mode. The files can be accessed from your PC using tools such as mpremote and rshell.
Peter Hinch
Index to my micropython libraries.

bradstew
Posts: 41
Joined: Thu Nov 29, 2018 9:29 pm

Re: is os.sync a non-blocking?

Post by bradstew » Thu Dec 09, 2021 5:24 pm

Thanks. Now it makes sense.
The FAQ link was difficult to see on my browser.

Post Reply