Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:08:23+00:00 2026-05-23T13:08:23+00:00

I am writing a script that processes some mmaps concurrently with multiprocessing.Process and updates

  • 0

I am writing a script that processes some mmaps concurrently with multiprocessing.Process and updates a result list stored in an mmap and locked with a mutex.

My function to write to the result list looks like this

def update_result(result_mmap, new_value, new_value_index, sema):
    sema.acquire()
    result_mmap.seek(0)
    old_result = result_mmap.readline().split("\t")
    old_result[new_value_index] = new_value
    new_result = "\t".join(map(str, old_result))
    result_mmap.resize(len(new_result))
    result_mmap.seek(0)
    result_mmap.write(new_result)
    sema.release()

This works SOMETIMES, but other times, depending on the order of execution of the processes, it seems that the result_mmap isn’t resizing properly. I am not sure where to look from here- I know that a race condition exists but I don’t know why.

Edit: This is the function that calls update_result:

def apply_function(mmapped_files, function, result_mmap, result_index, sema):
    for mf in mmapped_files:
        accumulator = int(mf.readline())
        while True:
            line = mf.readline()
            if line is None or line == '':
                break
            num = int(line)
            accumulator = function(num, accumulator)
        update_result(result_mmap, result_index, inc, sema)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:08:24+00:00Added an answer on May 23, 2026 at 1:08 pm

    Maybe I’m wrong, but are you sure that the semaphore really works between the processes (is it a system mutex?). Because if it’s not, processes do not share the same memory space. What you might want to consider using would be the threading library, in order for the threads to use the same semaphore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a script that calls another java program, to perform some tasks.
I am writing a shell script for a couple of long running processes. First
I'm in the process of writing an image script for a website I'm making,
I'm writing some monitoring scripts in Python and I'm trying to find the cleanest
Greetings, I've taken over from a prior team and writing ETL jobs which process
I'm trying to write a script that will grab logs across a network and
We're planning to build a web application that needs to be highly secure because
I created a little proxy node script, which looksup the request.url and either passes
From my limited understanding of nginx I know that nginx seperates itself from Apache
After using batch files for many years I was surprised to discover that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.