Exiting a multiprocessed python application safely

0 votes
When we use-  os._exit(<num>) ::

Exit the process with status n, without calling cleanup handlers, flushing stdio buffers, etc.

and that sys.exit() ::

“only” raises an exception, it will only exit the process when called from the main thread

Now, how do I close a multi-processed application that will ensure all processes are closed (none left orphaned) and that it exits in the best state possible?

Also, I am creating the processes using the python multiprocessing library, by creating classes which inherit from multiprocessing Process.
May 6 in Python by ana1504.k
• 7,430 points
15 views

1 answer to this question.

0 votes
I ended up creating a Pipe for every Process. Then when the main Process shuts down it can send a message to all the children Processes that they should shut down too.

In order to make that work right you've got to put a periodic check into the children Processes' "do loop" to see if there are messages in the pipe, and if so, check them to see if it's a "quit now" message.
answered May 6 by SDeb
• 12,280 points

Related Questions In Python

0 votes
1 answer

Exiting a python program

Use the quit() function. This function can ...READ MORE

answered May 8, 2018 in Python by Nietzsche's daemon
• 4,260 points
15 views
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,810 points
89 views
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,420 points
69 views
+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,710 points
1,096 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 127 views
0 votes
1 answer

Is there a string 'contains' in python?

In this case, you can use the ...READ MORE

answered Sep 25, 2018 in Python by SDeb
• 12,280 points
51 views
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 28, 2018 in Python by SDeb
• 12,280 points
59 views