Solved

How to start background processes in Python?

Posted on 2014-12-24
3
338 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

749 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