How to use the wrapt.synchronized function in wrapt

To help you get started, we’ve selected a few wrapt 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 ionelmc / python-lazy-object-proxy / tests / test_synchronized_lock.py View on Github external
    @classmethod
    def function2(cls):
        print('function2')

    @wrapt.synchronized
    @staticmethod
    def function3():
        print('function3')

c1 = C1()

@wrapt.synchronized
class C2(object):
    pass

@wrapt.synchronized
class C3:
    pass

class C4(object):

    # XXX This yields undesirable results due to how class method is
    # implemented. The classmethod doesn't bind the method to the class
    # before calling. As a consequence, the decorator wrapper function
    # sees the instance as None with the class being explicitly passed
    # as the first argument. It isn't possible to detect and correct
    # this.

    @classmethod
    @wrapt.synchronized
    def function2(cls):
        print('function2')
github cyanogen / uchroma / uchroma / server / device_base.py View on Github external
    @synchronized
    def run_report(self, report: RazerReport, delay: float = None) -> bool:
        """
        Runs a previously initialized RazerReport on the device

        :param report: the report to run
        :param delay: custom delay to enforce between commands
        :return: True if successful
        """
        with self.device_open():
            return report.run(delay=delay, timeout_cb=self._get_timeout_cb())
github echolox / smartbcr2k / smci / clock.py View on Github external
    @synchronized
    def unpause(self):
        self.running = True
github cyanogen / uchroma / uchroma / log.py View on Github external
    @synchronized
    @classmethod
    def get(cls, tag):
        """
        Get the global logger instance for the given tag

        :param tag: the log tag
        :return: the logger instance
        """
        if tag not in cls._LOGGERS:
            if cls._use_color:
                handler = colorlog.StreamHandler()
                handler.setFormatter(colorlog.ColoredFormatter( \
                    ' %(log_color)s%(name)s/%(levelname)-8s%(reset)s |'
                    ' %(log_color)s%(message)s%(reset)s'))
            else:
                handler = logging.StreamHandler()
github hsnlab / escape / escape / escape / util / com_logger.py View on Github external
  @wrapt.synchronized(__lock)
  def increase_cntr (self):
    """
    Increase file counter.

    :return: increased counter value
    :rtype: int
    """
    self.__cntr += 1
    return self.__cntr
github echolox / smartbcr2k / smci / clock.py View on Github external
    @synchronized
    @bpm.setter
    def bpm(self, value):
        self._bpm = value
github cyanogen / uchroma / uchroma / server / headset.py View on Github external
    @synchronized
    def run_with_result(self, command: BaseCommand, *args) -> bytes:
        """
        Run a command against the Kraken hardware and fetch the result

        :param command: The command tuple
        :param args: Argument list (varargs)

        :return: Raw response bytes
        """
        try:
            with self.device_open():
                if not self._run_command(command, *args):
                    return None

                self._last_cmd_time = smart_delay(DELAY_TIME, self._last_cmd_time, 0)
                resp = self._dev.read(REPORT_LENGTH_IN, timeout_ms=500)
github echolox / smartbcr2k / smci / clock.py View on Github external
    @synchronized
    def tick(self):
        if self.tick_count == 0:
            self._at_measure_start()

        self.tick_count = (self.tick_count + 1) % (self.signature.top * 24 / (self.signature.bottom / 4))
        self.last_tick_time = time()
github echolox / smartbcr2k / smci / clock.py View on Github external
    @synchronized
    def start(self):
        self.measure_count = 0
        self.tick_count = 0
        self.running = True
github cyanogen / uchroma / uchroma / server / headset.py View on Github external
    @synchronized
    def run_command(self, command: BaseCommand, *args) -> bool:
        """
        Run a command against the Kraken hardware

        :param command: The command tuple
        :param args: Argument list (varargs)

        :return: True if successful
        """
        with self.device_open():
            return self._run_command(command, *args)