How to use the fasteners.process_lock function in fasteners

To help you get started, we’ve selected a few fasteners examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MozillaSecurity / grizzly / grizzly / common / reporter.py View on Github external
def _submit(self, report, test_cases):
        # prepare data for submission as CrashInfo
        crash_info = self.create_crash_info(report, self.target_binary)

        # search for a cached signature match and if the signature
        # is already in the cache and marked as frequent, don't bother submitting
        with fasteners.process_lock.InterProcessLock(os.path.join(tempfile.gettempdir(), "fm_sigcache.lock")):
            collector = Collector()
            cache_sig_file, cache_metadata = collector.search(crash_info)
            if cache_metadata is not None:
                if cache_metadata["frequent"]:
                    log.info("Frequent crash matched existing signature: %s",
                             cache_metadata["shortDescription"])
                    if not self.force_report:
                        return
                elif "bug__id" in cache_metadata:
                    log.info("Crash matched existing signature (bug %s): %s",
                             cache_metadata["bug__id"],
                             cache_metadata["shortDescription"])
                    # we will still report this one, but no more
                    cache_metadata["frequent"] = True
                # there is already a signature, initialize count
                cache_metadata.setdefault("_grizzly_seen_count", 0)
github MozillaSecurity / grizzly / grizzly / common / status.py View on Github external
def __enter__(self):
        self._lock = fasteners.process_lock.InterProcessLock("%s.lock" % (self._file,))
        self._lock.acquire()
        try:
            with open(self._file, "r") as in_fp:
                data = json.load(in_fp)
            self.error = data["error"]
            self.failed = data["failed"]
            self.passed = data["passed"]
        except IOError:
            LOG.debug("%r does not exist", self._file)
        except ValueError:
            LOG.debug("failed to load stats from %r", self._file)
        return self
github MozillaSecurity / grizzly / grizzly / common / status.py View on Github external
def load(cls, data_file):
        """Read Grizzly status report.

        Args:
            data_file (str): JSON file that contains status data.

        Returns:
            Status: Loaded status object or None
        """
        if not os.path.isfile(data_file):
            return None
        with fasteners.process_lock.InterProcessLock("%s.lock" % (data_file,)):
            with open(data_file, "r") as out_fp:
                try:
                    data = json.load(out_fp)
                except ValueError:
                    LOG.debug("failed to json")
                    return None
        status = cls(data_file, data["start_time"])
        for attr, value in data.items():
            setattr(status, attr, value)
        return status