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

  • SEARCH
  • Home
  • 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 8360939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:35:05+00:00 2026-06-09T11:35:05+00:00

I am working segmenting large ctype arrays and processing them in parallel. I am

  • 0

I am working segmenting large ctype arrays and processing them in parallel. I am receiving the error below and believe it it because one segment of the array is finishing processing before another. I tried using process.join() to have the first set of processes wait, but that is not working. Ideas?

Exception RuntimeError: RuntimeError('cannot join current thread',) in <Finalize object, dead> ignored

Using:

    ....

        with closing(multiprocessing.Pool(initializer=init(array))) as p:
            del array #Since the array is now stored in a shared array destroy the array ref for memory reasons

            step = y // cores
            if step != 0:
                jobs =[]
                for i in range (0, y, step):
                    process = p.Process(target=stretch, args= (shared_arr,slice(i, i+step)),kwargs=options)
                    jobs.append(process)
                    process.start()

                for j in jobs:
                    j.join()

    del jobs
    del process

Update:

 #Create an ctypes array
        array = ArrayConvert.SharedMemArray(array)
        #Create a global of options
        init_options(options) #options is a dict
        with closing(multiprocessing.Pool(initializer=init(array))) as p:
            del array #Since the array is not stored in a shared array destroy the array ref for memory reasons


            step = y // cores
            if step != 0:
                for i in range (0, y, step):
                    #Package all the options into a global dictionary

                    p.map_async(stretch,[slice(i, i+step)])

                    #p.apply_async(stretch,args=(shared_arr,slice(i, i+step)),kwargs=options)

        p.join()        

def init_options(options_):
    global kwoptions
    kwoptions = options_

The function that I am passing to map_async is stored in a different module, so I am struggling to get the global kwoptions passed to that function. It does not seem right to be passing globals around between modules like this (unpythonic). Is this the way to be able to pass kwargs through map_async.

Should I be reworking the multiprocessing using something different (apply or Process)?

  • 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-06-09T11:35:07+00:00Added an answer on June 9, 2026 at 11:35 am

    initializer argument for Pool() accepts a function; replace initializer=init(array) with initializer=init, initargs=(array,)

    To pass keyword arguments to a function f() used with pool.*map* family you could create a wrapper mp_f():

    #!/usr/bin/env python
    import logging
    import multiprocessing as mp
    from contextlib import closing
    
    def init(shared_array_):
        # globals that should be available in worker processes should be
        # initialized here
        global shared_array
        shared_array = shared_array_
    
    def f(interval, a=None, b=None):
        mp.get_logger().info("interval=%r, a=%r, b=%r" % (interval, a, b))
        shared_array[interval] = [a + interval.start]*b # fake computations
    
    def mp_f(arg_kwargs):
        try:
            arg, kwargs = arg_kwargs
            return f(arg, **kwargs) # pass keyword args to f()
        except Exception:
            mp.get_logger().error("f%r failed" % (arg_kwargs,))
    
    def main():
        mp.log_to_stderr().setLevel(logging.INFO)
    
        N = 10**6
        array = mp.RawArray('i', N) # create shared array
    
        # create workers pool; use all available CPU cores
        with closing(mp.Pool(initializer=init, initargs=(array,))) as p:
            options = dict(a=5, b=N//4) # dummy options
            step = options['b']
            args = ((slice(i, i+step), options) for i in range(0, N, step))
            for _ in p.imap_unordered(mp_f, args): # submit jobs
                pass
        p.join()
        mp.get_logger().info(array[::step])
    
    if __name__=="__main__":
        mp.freeze_support() # for py2exe and the-like on Windows
        main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a rather large project and one of the bigger project folders uses
Working with H2 I get this error when I try to write a row
Working sample using one Table SELECT t.* FROM ( SELECT TITLE.name, (TITLE.value-TITLE.msp) AS Lower,
Working with box2d and cocos2d, I've calculated two vectors: one is the vector pointing
Right now I'm working on a program for my Visual Information Processing course. We're
Working on a project with git, I have two feature branches, call them dev-a
Working with spring, below, the code of applicationContext-service.xml: <bean id=mediaObjectService class=path.MediaObjectServiceImpl> <property name=mediaObjectDao >
I'm working on streaming live video to ipad/iphone using apple's http live streaming. One
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with an undisclosed API, I found a function that can set the number

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.