Solved

How to start background processes in Python?

Posted on 2014-12-24
3
307 Views
Last Modified: 2014-12-28
Hello,

I'm trying to
  * read a file
  * write some data into a folder
  * start another process to process the data
  * resume reading the file while the process works on the data

Is there a good way to go about doing this? Would it be better than starting a bunch of threads?

The reason I'm thinking about it this way, is that I don't really need the processes to communicate with each other, once started, the processes will be working on their own set of data; and I'm hoping Unix would manage running multiple scripts better than Python would manage threads.

Appreciate any advice on this!
0
Comment
Question by:Errang Genevre
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 350 total points
ID: 40517414
You spawn a process by invoking the subprocess function.

You have a potential race condition in that the second process won't know exactly when the Python process is done writing the file (unless these are fixed-size files), so you might want to use a convention like writing a zero-byte sentinel file to alert the subprocess as to when the file is done being written. Unless, of course, you won't be kicking off the 2nd process until the Python process finishes writing the file.
0
 
LVL 25

Assisted Solution

by:clockwatcher
clockwatcher earned 150 total points
ID: 40518156
Might be a little overkill for what you're after but it sounds like a good candidate for a message queuing system:  https://www.rabbitmq.com/tutorials/tutorial-two-python.html
0
 

Author Closing Comment

by:Errang Genevre
ID: 40520677
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Changing $PATH variable - OS X 2 65
Python 2.7 - Passing arguments 8 57
How does this Python sort work? 5 61
Need script to search multiple files in one drive 13 31
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now