parameters: ()
docstring: Finds which rented phones haven't been touched for a while and sends a command to release them
docstring_summary: Finds which rented phones haven't been touched for a while and sends a command to release them
docstring_tokens: Finds which rented phones haven t been touched for a while and sends a command to release them
function: def cleanup_rented_phones():
      """
      Finds which rented phones haven't been touched for a while and sends a command to release them
  
      """
      for p in models.PhoneData.objects.exclude(owner_id__isnull=True).exclude(sms_status=models.PhoneData.SMS_INITIAL):
          # check if the phone is in use:
          if settings.REDIS.get(FORMAT_PHONE_LOCK.format(p.uniq_id)):
              # keep it locked
              continue
          # check if the phone is not being locked/unlocked currently
          if get_phone_transient_state(p.uniq_id) == PHONE_STATE_STABLE:
              # release it
              release_phone(p)
function_tokens: def cleanup_rented_phones ( ) : for p in models . PhoneData . objects . exclude ( owner_id__isnull = True ) . exclude ( sms_status = models . PhoneData . SMS_INITIAL ) : # check if the phone is in use: if settings . REDIS . get ( FORMAT_PHONE_LOCK . format ( p . uniq_id ) ) : # keep it locked continue # check if the phone is not being locked/unlocked currently if get_phone_transient_state ( p . uniq_id ) == PHONE_STATE_STABLE : # release it release_phone ( p )