Compare commits
2 Commits
nilmtools-
...
nilmtools-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8b9c5d4898 | ||
cf2c28b0fb |
@@ -6,7 +6,7 @@ Prerequisites:
|
|||||||
|
|
||||||
# Runtime and build environments
|
# Runtime and build environments
|
||||||
sudo apt-get install python2.7 python2.7-dev python-setuptools
|
sudo apt-get install python2.7 python2.7-dev python-setuptools
|
||||||
sudo apt-get install python-numpy python-scipy
|
sudo apt-get install python-numpy python-scipy python-daemon
|
||||||
|
|
||||||
nilmdb (1.8.1+)
|
nilmdb (1.8.1+)
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@ import threading
|
|||||||
import select
|
import select
|
||||||
import signal
|
import signal
|
||||||
import Queue
|
import Queue
|
||||||
|
import daemon
|
||||||
|
|
||||||
def parse_args(argv = None):
|
def parse_args(argv = None):
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
@@ -29,6 +30,8 @@ def parse_args(argv = None):
|
|||||||
Intended for use with ethstream (generator) and nilm-insert
|
Intended for use with ethstream (generator) and nilm-insert
|
||||||
(consumer). Commands are executed through the shell.
|
(consumer). Commands are executed through the shell.
|
||||||
""")
|
""")
|
||||||
|
parser.add_argument("-d", "--daemon", action="store_true",
|
||||||
|
help="Run in background")
|
||||||
parser.add_argument("-l", "--lock", metavar="FILENAME", action="store",
|
parser.add_argument("-l", "--lock", metavar="FILENAME", action="store",
|
||||||
default=tempfile.gettempdir() +
|
default=tempfile.gettempdir() +
|
||||||
"/nilm-pipewatch.lock",
|
"/nilm-pipewatch.lock",
|
||||||
@@ -74,16 +77,8 @@ def watcher_thread(queue, procs):
|
|||||||
return
|
return
|
||||||
time.sleep(0.25)
|
time.sleep(0.25)
|
||||||
|
|
||||||
def main(argv = None):
|
def pipewatch(args):
|
||||||
args = parse_args(argv)
|
# Run the processes, etc
|
||||||
|
|
||||||
with open(args.lock, "w") as lockfile:
|
|
||||||
if not nilmdb.utils.lock.exclusive_lock(lockfile):
|
|
||||||
printf("pipewatch process already running (according to %s)\n",
|
|
||||||
args.lock)
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
with open(os.devnull, "r") as devnull:
|
with open(os.devnull, "r") as devnull:
|
||||||
generator = subprocess.Popen(args.generator, shell = True,
|
generator = subprocess.Popen(args.generator, shell = True,
|
||||||
bufsize = -1, close_fds = True,
|
bufsize = -1, close_fds = True,
|
||||||
@@ -146,6 +141,24 @@ def main(argv = None):
|
|||||||
if gret == 0 and cret == 0:
|
if gret == 0 and cret == 0:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def main(argv = None):
|
||||||
|
args = parse_args(argv)
|
||||||
|
|
||||||
|
lockfile = open(args.lock, "w")
|
||||||
|
if not nilmdb.utils.lock.exclusive_lock(lockfile):
|
||||||
|
printf("pipewatch process already running (according to %s)\n",
|
||||||
|
args.lock)
|
||||||
|
sys.exit(0)
|
||||||
|
try:
|
||||||
|
# Run as a daemon if requested, otherwise run directly.
|
||||||
|
if args.daemon:
|
||||||
|
with daemon.DaemonContext(files_preserve = [ lockfile ]):
|
||||||
|
pipewatch(args)
|
||||||
|
else:
|
||||||
|
pipewatch(args)
|
||||||
|
finally:
|
||||||
|
# Clean up lockfile
|
||||||
try:
|
try:
|
||||||
os.unlink(args.lock)
|
os.unlink(args.lock)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
Reference in New Issue
Block a user