def try_acquire(self, permits=1, timeout=0):
        """
        Tries to acquire one or the given number of permits, if they are available, and returns immediately, with the
        value ``true``, reducing the number of available permits by the given amount.

        If there are insufficient permits and a timeout is provided, the current thread becomes disabled for thread
        scheduling purposes and lies dormant until one of following happens:
            * some other thread invokes the release() method for this semaphore and the current thread is next to be
            assigned a permit, or
            * some other thread interrupts the current thread, or
            * the specified waiting time elapses.

        If there are insufficient permits and no timeout is provided, this method will return immediately with the value
        ``false`` and the number of available permits is unchanged.

        :param permits: (int), the number of permits to acquire (optional).
        :param timeout: (long), the maximum time in seconds to wait for the permit(s) (optional).
        :return: (bool), ``true`` if desired amount of permits was acquired, ``false`` otherwise.
        """
        check_not_negative(permits, "Permits cannot be negative!")
        return self._encode_invoke(semaphore_try_acquire_codec, permits=permits, timeout=to_millis(timeout))