#!$HOME/app/anaconda2/python
#!/bin/env python2

#
# By W.Wang(Kevin), on 2017-11-02
# TODO: use python 'affinity' package to bind a process with a certain logic CPU.
# TODO: it is a pity that 'affinity' relies on package pywin32 for Windows platform.
# TODO: in Linux, use command 'taskset'
#

#
# TODO: add option --run-as=user-name
#

import sys
import time
from pcmd.env_pc import ParaCmdEnv
from pcmd.client import Client
from pcmd.daemon import Daemon

print 'Parallel Command:'
print 'When there is no reply, please try adding \"2>&1\" at the end of a command.'
env = ParaCmdEnv.GetInstance()
client = Client()
client.qHBeat()
# the sript itself is sys.argv[0]
if(len(sys.argv) < 2):
    print 'A command is needed.'
    sys.exit(0)
cmd = sys.argv[1]
targ = None
if(len(sys.argv) >= 3):
    targ = sys.argv[2]
client.sendCmd(cmd, targ)
time.sleep(1.2*Daemon.sleep_duration)
client.rcvReply()





