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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:27:52+00:00 2026-06-12T16:27:52+00:00

I am using python 2.7 multiprocessing module.I want to start a process and then

  • 0

I am using python 2.7 multiprocessing module.I want to start a process and then terminate it and then start it again with new arguments.

p = Process(target=realwork, args=(up, down, middle, num))
def fun1():
    p.start()

def fun2():
    p.terminate()

And in the course of the program flow (through loops and events) I call the functions in this order:

fun1()
fun2()
fun1()
fun2()

If I try that i get an error saying I cannot call same process multiple times. Is there a workaround?

  • 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-12T16:27:54+00:00Added an answer on June 12, 2026 at 4:27 pm

    So – you probably had read somewhere that "using global variables is not a good practice" – and this is why. Your "p" variable only holds one "Process" instance, and it can only be started (and terminated) once.

    If you refactor your code so that "fun1" and "fun2" take the process upon which they act as a parameter, or maybe in an O.O. way, in which fun1 and fun2 are methods and the Process is an instance variable, you would not have any of these problems.

    In this case, O.O. is quick to see and straightforward to use:

    class MyClass(object):
        def __init__(self):
            self.p = Process(target=realwork,args=(up,down,middle,num))
        def fun1(self):
            self.p.start()
    
        def fun2(self):
            self.p.terminate()
    

    And then, wherever you need a pair of calls to "fun1" and "fun2", you do:

    action = Myclass()
    action.fun1()
    action.fun2() 
    

    instead. This would work even inside a for loop, or whatever.

    *edit – I just saw you are using this as answer to a button press in a Tkinter
    program, so, you have to record the Process instance somewhere between button clicks.
    Without having your code to refactor, and supposing you intend to persist
    on your global variable approach, you can simply create the Process instance inside
    "fun1" – this would work:

    def fun1():
        global p
        p = Process(target=realwork,args=(up,down,middle,num))
        p.start()
    
    def fun2():
        p.terminate()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Python's multiprocessing module to process large numpy arrays in parallel. The
From within a Python GUI (PyGTK) I start a process (using multiprocessing). The process
I am having trouble with the Python multiprocessing module. I am using the Process
When using python-daemon , I'm creating subprocesses likeso: import multiprocessing class Worker(multiprocessing.Process): def __init__(self,
I want to use Python's multiprocessing to do concurrent processing without using locks (locks
I'm getting the following error when using the multiprocessing module within a python daemon
I am sending simple objects between processes using pipes with Python's multiprocessing module. The
modules exists inside new processes before import, using python-multiprocessing on osx. Here's an example:
I create a couple of worker processes using Python's Multiprocessing module 2.6. In each
newcomer and first ever question here. I am using the multiprocessing module of Python

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.