(self)
| 649 | self.counter = 0 |
| 650 | |
| 651 | def __enter__(self): |
| 652 | # Acquire the lock |
| 653 | while True: |
| 654 | try: |
| 655 | self.fd = os.open(self.path, os.O_CREAT | os.O_EXCL | os.O_WRONLY) |
| 656 | break |
| 657 | except FileExistsError: |
| 658 | time.sleep(0.1) |
| 659 | # Return the locking count number |
| 660 | try: |
| 661 | self.counter = int(utils.read_file(f'{self.path}_counter')) |
| 662 | except Exception: |
| 663 | pass |
| 664 | return self.counter |
| 665 | |
| 666 | def __exit__(self, *a): |
| 667 | # Increment locking count number before releasing the lock |