@@ -212,7 +212,7 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
212212 Writable :term: `bytes-like object ` is now accepted.
213213
214214
215- .. method :: flush([offset[, size]])
215+ .. method :: flush([offset[, size]], *, flags=MS_SYNC )
216216
217217 Flushes changes made to the in-memory copy of a file back to disk. Without
218218 use of this call there is no guarantee that changes are written back before
@@ -221,6 +221,12 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
221221 whole extent of the mapping is flushed. *offset * must be a multiple of the
222222 :const: `PAGESIZE ` or :const: `ALLOCATIONGRANULARITY `.
223223
224+ The *flags * parameter specifies the synchronization behavior.
225+ *flags * must be one of the :ref: `MS_* constants <ms-constants >` available
226+ on the system.
227+
228+ On Windows, the *flags * parameter is ignored.
229+
224230 ``None `` is returned to indicate success. An exception is raised when the
225231 call failed.
226232
@@ -235,6 +241,9 @@ To map anonymous memory, -1 should be passed as the fileno along with the length
235241 specified alone, and the flush operation will extend from *offset *
236242 to the end of the mmap.
237243
244+ .. versionchanged :: next
245+ Added *flags * parameter to control synchronization behavior.
246+
238247
239248 .. method :: madvise(option[, start[, length]])
240249
@@ -461,3 +470,22 @@ MAP_* Constants
461470 :data: `MAP_TPRO `, :data: `MAP_TRANSLATED_ALLOW_EXECUTE `, and
462471 :data: `MAP_UNIX03 ` constants.
463472
473+ .. _ms-constants :
474+
475+ MS_* Constants
476+ ++++++++++++++
477+
478+ .. data :: MS_SYNC
479+ MS_ASYNC
480+ MS_INVALIDATE
481+
482+ These flags control the synchronization behavior for :meth: `mmap.flush `:
483+
484+ * :data: `MS_SYNC ` - Synchronous flush: writes are scheduled and the call
485+ blocks until they are physically written to storage.
486+ * :data: `MS_ASYNC ` - Asynchronous flush: writes are scheduled but the call
487+ returns immediately without waiting for completion.
488+ * :data: `MS_INVALIDATE ` - Invalidate cached data: invalidates other mappings
489+ of the same file so they can see the changes.
490+
491+ .. versionadded :: next
0 commit comments