Playing with threads
Devin Jeanpierre
jeanpierreda at gmail.com
Wed Jan 7 21:09:24 EST 2015
I can't tell what you mean, but you can start a process via
subprocess.Popen, do some work, and wait for it to finish.
https://docs.python.org/2/library/subprocess.html
Note that you don't need the stdout (or likely the stdin) of the
process, you just need the return code -- whether or not grep
succeeded -- so you can redirect stdout and stderr to os.devnull and
avoid using .communicate(). Also, if you can't use .communicate(),
but need to access stdout, this is the most common reason to need
threads with subprocess.
-- Devin
On Wed, Jan 7, 2015 at 8:00 PM, Ganesh Pal <ganesh1pal at gmail.com> wrote:
> Hi friends,
>
> 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
>
> Questions:
>
> 1. Can the above be achieved without threads ? I prefer keep ing code simple
> .threads can become confusion when this workflow grows larger
>
> Regards,
> Ganesh
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list