The sync man page says:
sync() causes all buffered modifications to file metadata and data to be written to the underlying file systems.
Does Python have a call to do this?
P.S. Not fsync, I see that.
There are two basic types of methods in the Parallels Python API: synchronous and asynchronous. When a synchronous method is invoked, it completes executing before returning to the caller. An asynchronous method starts a job in the background and returns to the caller immediately.
That first part is the most critical thing to understand - Python code can now basically run in one of two "worlds", either synchronous or asynchronous. You should think of them as relatively separate, having different libraries and calling styles but sharing variables and syntax.
It's the language, in python most apis are synchronous by default, and the async version is usually an "advanced" topic.
It makes use of Python async features using asyncio/await provided in Python 3. The time and queue modules have been replaced with the asyncio package. This gives your program access to asynchronous friendly (non-blocking) sleep and queue functionality.
Python 3.3 has os.sync, see the docs. The source confirms it is the same thing.
For Python 2 you can to make an external call to the system:
from subprocess import check_call
check_call(['sync'])
As said, Python 3.3 has the call - on Python 2.x, since it is a simple system call, requiring no data to be passed back and forth, you can use ctypes to make the call:
>>> import ctypes
>>> libc = ctypes.CDLL("libc.so.6")
>>> libc.sync()
0
Combining the two answers, I use the following at the top of my module:
if hasattr(os, 'sync'):
sync = os.sync
else:
import ctypes
libc = ctypes.CDLL("libc.so.6")
def sync():
libc.sync()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With