Here's an abstraction from my code. There may be better ways to do it,
but it works.
Let's say you wanted to start a miner to watch the system log...
from subprocess import *
from multiprocessing import Process, Queue
def doSomething(self, q):
p1 = Popen([ 'tail', '-f', '/var/log/messages'), stdout=PIPE)
p2 = Popen(['grep', '-i', 'foo'], stdin=p1.stdout, stdout=PIPE)
q.put(dict(pid=p1.pid))
def startDoSomething(self):
q = Queue()
p = Process(target=doSomething, args=(q,))
p.start()
db.settings.insert(pid=q.get()['pid'],
timestamp=datetime.datetime.now())
db.commit()
The reason I did it this way is that I need to control the start/stop
of this secondary process. There will only be one instance of it
running at any given time and special permissions are needed to access
the control functions.
--Nite
(Note, this example doesn't really make sense since we aren't doing
anything with the stdout from the grep command, but illustrates the
point of how to start a secondary process which was the purpose)
On May 23, 11:26 pm, Massimo Di Pierro <
massimo.dipie...@gmail.com>
wrote: