Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83314 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2015-01-08 13:24 +1100 |
| Last post | 2015-01-08 13:24 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Playing with threads Chris Angelico <rosuav@gmail.com> - 2015-01-08 13:24 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-01-08 13:24 +1100 |
| Subject | Re: Playing with threads |
| Message-ID | <mailman.17461.1420683901.18130.python-list@python.org> |
On Thu, Jan 8, 2015 at 1:00 PM, Ganesh Pal <ganesh1pal@gmail.com> wrote:
> I'm trying to use threads to achieve the below work flow
>
> 1. Start a process , while its running grep for a string 1
> 2. Apply the string 1 to the command in step 1 and exit step 2
> 3. Monitor the stdout of step1 and print success if the is pattern found
If by "grep" you mean "search", then this would be best done by
spawning a subprocess and monitoring its output.
https://docs.python.org/3/library/subprocess.html
Set stdout=PIPE, then read from the stdout member, and you'll be
reading the program's output. Something like this:
with subprocess.Popen(["find","/","-name","*.py"],stdout=subprocess.PIPE)
as findpy:
for line in findpy.stdout:
# do something with line
You'll get lines as they're produced, and can use standard string
manipulation on them. I don't know what your step 2 is, but you can
set stdin to be a pipe as well, and then you just write to your end
and the process will receive that on its standard input.
No threads needed; just your Python process and the subprocess.
ChrisA
Back to top | Article view | comp.lang.python
csiph-web