Example #1
0
 def test_term_all_procs_multi_procs(self):
     proc1 = start_proc("sleep 1000")
     proc2 = start_proc("sleep 1000")
     proc3 = start_proc("sleep 1000")
     proc4 = start_proc("sleep 1000")
     proc5 = start_proc("sleep 1000")
     term_all_procs()
     self.assertEqual(proc1.poll(), -15)
     self.assertEqual(proc2.poll(), -15)
     self.assertEqual(proc3.poll(), -15)
     self.assertEqual(proc4.poll(), -15)
     self.assertEqual(proc5.poll(), -15)
Example #2
0
    def get_supported_algos(cls):
        if cls._cached_ccminer_algos:
            return cls._cached_ccminer_algos

        proc = start_proc("/usr/local/bin/tpruvot-ccminer -h",
                          pipe_stdout=True)
        reading_algos = False
        supported_algos = set()

        for line in proc.stdout:
            line = line.strip()

            if line.split(b" ")[0] == b"-d,":
                break

            if reading_algos:
                supported_algos.add(line.split(b" ")[0].decode("UTF-8"))

            if line.split(b" ")[0] == b"-a,":
                reading_algos = True

        term_proc(proc)

        cls._cached_ccminer_algos = supported_algos
        return supported_algos
Example #3
0
    def test_term_all_procs_multi_procs_trapped(self):
        logging.getLogger().setLevel(logging.ERROR)

        def trap():
            signal.signal(signal.SIGTERM, signal.SIG_IGN)

        proc1 = start_proc("sleep 1000", preexec_fn=trap)
        proc2 = start_proc("sleep 1000")
        proc3 = start_proc("sleep 1000", preexec_fn=trap)
        proc4 = start_proc("sleep 1000")
        proc5 = start_proc("sleep 1000")
        term_all_procs(term_wait_time=.05)
        self.assertEqual(proc1.poll(), -9)
        self.assertEqual(proc2.poll(), -15)
        self.assertEqual(proc3.poll(), -9)
        self.assertEqual(proc4.poll(), -15)
        self.assertEqual(proc5.poll(), -15)
        logging.getLogger().setLevel(logging.WARNING)
Example #4
0
    def _return_when_miner_is_using_gpu(self):
        assert self.miner_proc and self.miner_proc.poll(
        ) is None, "Process is not running"

        checker = start_proc("nvidia-smi pmon", pipe_stdout=True)

        for line in checker.stdout:
            if str(self.miner_proc.pid).encode('utf-8') in line:
                break

        term_proc(checker)
Example #5
0
    def test_term_proc_term_disabled(self):
        logging.getLogger().setLevel(logging.ERROR)

        def trap():
            signal.signal(signal.SIGTERM, signal.SIG_IGN)

        proc = start_proc("sleep 1000", preexec_fn=trap)
        self.assertIsNone(proc.poll())
        term_proc(proc, term_wait_time=0.1)
        self.assertEqual(proc.poll(), -9)
        logging.getLogger().setLevel(logging.WARNING)
Example #6
0
    def benchmark(self):
        cmd = self._get_run_cmd(self.path_to_exec,
                                self.algo,
                                "",
                                "",
                                "",
                                "",
                                kwargs={
                                    "--benchmark": "",
                                    "--no-color": ""
                                })
        LOG.debug("Benchmarking \033[92m%s\033[0m...", self.algo)
        cache_key = "BENCHHR%s" % (cmd)
        cached_benchmark = MinerStore.get(cache_key)
        if cached_benchmark:
            b = Rate(cached_benchmark)
            LOG.debug("Benchmark found in cache: %s!", b)
            return b

        LOG.info("Benchmark not found for \033[92m%s\033[0m. Benchmarking...",
                 self.algo)

        bench_proc = start_proc(cmd, pipe_stdout=True)
        bm = Benchmarker()

        for line in bench_proc.stdout:
            line = line.strip().decode("UTF-8")

            if "Total:" in line:
                r = Rate(line.split(":")[-1].strip())
                bm.add_rate(r)

                final_hashrate = bm.get_benchmark()
                if final_hashrate:
                    break

        term_proc(bench_proc)

        MinerStore.set(cache_key, str(final_hashrate))
        LOG.info("Benchmark found: %s!", final_hashrate)

        return final_hashrate
Example #7
0
 def _start_and_return(self):
     cmd = self._get_mining_cmd()
     self.miner_proc = start_proc(cmd, pipe_stdout=True)
     self.logger_thread = self._start_and_return_logging_thread(
         self.miner_proc.stdout)
Example #8
0
 def test_start_proc_basic(self):
     proc = start_proc("sleep 0")
     proc.wait()
     self.assertIsNotNone(proc.poll())
     self.assertIsNone(proc.stdout)
     self.assertIsNone(proc.stderr)
Example #9
0
 def test_term_all_procs_one_proc(self):
     proc1 = start_proc("sleep 1000")
     term_all_procs()
     self.assertEqual(proc1.poll(), -15)
Example #10
0
 def test_term_proc_already_termed(self):
     proc = start_proc("sleep 1000")
     self.assertIsNone(proc.poll())
     term_proc(proc)
     self.assertEqual(proc.poll(), -15)
     term_proc(proc)
Example #11
0
 def test_start_proc_long(self):
     proc = start_proc("sleep 0.2")
     self.assertIsNone(proc.poll())
     proc.wait()
     self.assertIsNotNone(proc.poll())
Example #12
0
 def test_start_proc_stdout_pipe(self):
     proc = start_proc("echo test test", pipe_stdout=True)
     proc.wait()
     self.assertIsNotNone(proc.poll())
     self.assertEqual(proc.stdout.readline(), b"test test\n")
     self.assertIsNone(proc.stderr)