Uploaded image for project: 'Nuxeo Drive '
  1. Nuxeo Drive
  2. NXDRIVE-941

Use a context manager for Lock

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5.1
    • Fix Version/s: 3.0.5
    • Component/s: Framework
    • Tags:
    • Sprint:
      nxDrive 10.1.4
    • Story Points:
      1

      Description

      We can save many lines, and so reducing the code complexity and readability, by implementing a context manager for the Lock base class.

      The current code:

      self._lock.acquire()
      try:
          # ...
      finally:
          self._lock.release()
      

      Will be usable this way:

      with self._lock:
          # ...
      

      Pros:

      • resources are always closed and garbaged;
      • readability;
      • less code;
      • more pythonic;
      • possibility to use the context manager or not;
      • implementation time is quite small and not complex.

      Cons:

      • None.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours
                2h