A more detailed example of sharing data between processes on unix with mmap.

Open
#99,115 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
25/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
documentation

Research direction

Read Doc/library/mmap.rst and compare the existing process-sharing example with PR gh-99116. Done means the documentation contains a more detailed Unix mmap example that avoids calling readline without a newline in the buffer.

Written by the indexing model from the issue text.

Description

docs

Documentation

Doc/library/mmap.rst

The next example demonstrates how to create an anonymous map and exchange data between the parent and child processes::

import mmap
import os

mm = mmap.mmap(-1, 13)
mm.write(b"Hello world!")

pid = os.fork()

if pid == 0:  # In a child process
    mm.seek(0)
    print(mm.readline())
    mm.close()

I didn't like how the example calls readline without a newline in the buffer, so I re-wrote a more detailed example with a PR to follow.

  • PR: gh-99116
Dominant language
Python
Stars
77.2k
Forks
36k
Avg merge
1d 9h
Merged PRs (30d)
558

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.