Solved

How to start background processes in Python?

Posted on 2014-12-24
3
347 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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