Skip to content

Commit

Permalink
Add types to NullLock and rename to NullRLock
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham committed Jan 10, 2025
1 parent 272f2e6 commit 0d76f24
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tools/wptrunner/wptrunner/wptlogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import logging
from threading import Thread
from types import TracebackType
from typing import Optional, Type

from mozlog import commandline, stdadapter, set_default_logger
from mozlog.structuredlog import StructuredLogger, log_levels
Expand Down Expand Up @@ -77,7 +79,7 @@ def __init__(self, queue, level=logging.NOTSET):

def createLock(self):
# The queue provides its own locking
self.lock = NullLock()
self.lock = NullRLock()

def emit(self, record):
msg = self.format(record)
Expand All @@ -91,18 +93,22 @@ def emit(self, record):



class NullLock:
def acquire(self):
pass
class NullRLock:
"""Implementation of the threading.RLock API that doesn't actually acquire a lock,
for use in cases where there is another mechanism to provide the required
invariants."""

def release(self):
pass
def acquire(self, blocking: bool = True, timeout: float = -1) -> bool:
return True

def __enter__(self):
return self
def release(self) -> None:
return None

def __exit__(self, *args, **kwargs):
pass
def __enter__(self) -> bool:
return True

def __exit__(self, t: Optional[Type[BaseException]], v: Optional[BaseException], tb: Optional[TracebackType]) -> None:
return None


class LogQueueThread(Thread):
Expand Down

0 comments on commit 0d76f24

Please sign in to comment.