def test_set_workers_invalid():

    with pytest.raises(ValueError, match='workers must not be zero'):
        with fft.set_workers(0):
            pass

    with pytest.raises(ValueError, match='workers value out of range'):
        with fft.set_workers(-os.cpu_count() - 1):
            pass
def test_set_get_workers():
    cpus = os.cpu_count()
    assert fft.get_workers() == 1
    with fft.set_workers(4):
        assert fft.get_workers() == 4

        with fft.set_workers(-1):
            assert fft.get_workers() == cpus

        assert fft.get_workers() == 4

    assert fft.get_workers() == 1

    with fft.set_workers(-cpus):
        assert fft.get_workers() == 1
Exemple #3
0
    def run_python(self, output, fit_size=3):
        import time
        import multiprocessing
        nthreads = multiprocessing.cpu_count()
        with fft.set_workers(nthreads):
            started = time.time()
            self.get_ref()
            if output.endswith(".txt"):
                with open(output, "w") as fh:
                    for x, y, fname in self:
                        print(".", end="", flush=True)
                        fh.write("{:.6f} {:.6f} {} {}\n".format(
                            x, y, len(self.roi.positions), fname))
                        for (j, i), (cor, xp, yp, q) in zip(
                                self.roi.positions,
                                self.get_cor(fname, fit_size=fit_size)):
                            fh.write(
                                "{} {} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f}\n"
                                .format(j, i, xp, yp, *q))
            else:
                with open(output, "wb") as fh:
                    for x, y, fname in self:
                        print(".", end="", flush=True)
                        data = np.asarray(
                            [(j, i, xp, yp, *q)
                             for (j, i), (cor, xp, yp, q) in zip(
                                 self.roi.positions,
                                 self.get_cor(fname, fit_size=fit_size))],
                            dtype=float)
                        data.tofile(fh)
            dur = time.time() - started
            print()

            print(time.time() - started)
            return dur