Skip to content
Discussion options

You must be logged in to vote

Yes that seems to have been the problem. Wrapped all the functions I need with a lock as below and haven't run into any issues.

import _thread
import os

_LOCK = _thread.allocate_lock()


class ts_open:
    def __init__(self, file, mode="r"):
        self._file = file
        self._mode = mode

    def __enter__(self):
        _LOCK.acquire()
        self._file_obj = open(self._file, self._mode)
        return self._file_obj

    def __exit__(self, exc_type, exc_value, exc_tb):
        self._file_obj.close()
        _LOCK.release()


def ts_listdir(path=""):
    _LOCK.acquire()
    try:
        return os.listdir(path)
    finally:
        _LOCK.release()


def ts_remove(path):
    _LOCK.a…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by PepperoniPingu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant