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 7784821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:09:23+00:00 2026-06-01T20:09:23+00:00

I want to run 2 functions in parallel and use a returned value from

  • 0

I want to run 2 functions in parallel and use a returned value from one function (which is being stored in a list continuously) to be used in another function.

I have written some functions to achieve the above (taken help from some previous post on this forum).

u=[]

def func_a():
Num1=10000
for i1 in range(callNum1):
    ul = <some_function_returns_a_value>
    u.append(ul)

def func_b():
Num2=10000
time.sleep(30)
for i2 in range(Num2):
    ul1=u.pop(i2)
    print ul1

def RunP(*fns):
    proc = []
    for fn in fns:
        p = Process(target=fn)
        p.start()
        proc.append(p)
    for p in proc:
        p.join()

I call both the functions like the following

RunP(func_a, func_b)

But when I run this, I get this error :

RunP(func_a, func_b)
Process Process-2:
Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/multiprocessing-2.6.2.1-py2.4-linux-i686.egg/multiprocessing/process.py", line 237, in _bootstrap
    self.run()
  File "/usr/lib/python2.4/site-packages/multiprocessing-2.6.2.1-py2.4-linux-i686.egg/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "test.py", line 419, in func_b
    ul1=u.pop(i2)
IndexError: pop from empty list

Please help me achieve the intended task.

  • 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-01T20:09:24+00:00Added an answer on June 1, 2026 at 8:09 pm

    Sounds like you want to use a Queue.

    Here’s a quick’n’dirty example which is somewhat similar to your code:

    import multiprocessing
    
    def func_a(q):
        q.put(3)
        q.put(2)
        q.put(1)
    
    def func_b(q):
        v = q.get()
        print 'func_b prints:', v
        v = q.get()
        print 'func_b prints:', v
        v = q.get()
        print 'func_b prints:', v
    
    if __name__ == '__main__':
        q = multiprocessing.Queue()
        p1 = multiprocessing.Process(target = func_a, args = (q,))
        p1.start()
        p2 = multiprocessing.Process(target = func_b, args = (q,))
        p2.start()
        p1.join()
        p2.join()
    

    When I run this, it prints:

    func_b prints: 3
    func_b prints: 2
    func_b prints: 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# application, and I want to run a function which is
Let's say I want to run the same function on every one of my
I have one r function i want to run it automatically(scheduling) after every predefined
I want to run function inside web service (.asmx file) $.ajax({ type: POST, contentType:
I want to run a simple JavaScript function on a click without any redirection.
I have the following function that I only want to run inside <div id=imgWrapper>
I only want this function to run if .toolbar li does not have the
I have problem with fancybox. I want to write a function that will run
I'm using TestNG to run tests in parallel and want to be careful about
Once a minute I want to run a task, not blocking other GUI functions.

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.