Exemplo n.º 1
0
    def __init__(self, mcdr_server: 'MCDReforgedServer'):
        self.plugin_directories = []  # type: List[str]
        self.mcdr_server = mcdr_server
        self.logger = mcdr_server.logger

        # id -> Plugin plugin storage
        self.plugins = {}  # type: Dict[str, AbstractPlugin]
        # file_path -> id mapping
        self.plugin_file_path = {}  # type: Dict[str, str]
        # storage for event listeners, help messages and commands
        self.registry_storage = PluginRegistryStorage(self)

        self.last_operation_result = PluginOperationResult(self)

        # not used currently
        self.thread_pool = PluginThreadPool(
            self.mcdr_server, max_thread=constant.PLUGIN_THREAD_POOL_SIZE)

        # thread local storage, to store current plugin
        self.tls = ThreadLocalStorage()

        # plugin manipulation lock
        self.mani_lock = threading.RLock()

        file_util.touch_directory(PLUGIN_CONFIG_DIRECTORY)
Exemplo n.º 2
0
    def test_something(self):
        tls = ThreadLocalStorage()
        tls.put('a', 1)

        def another():
            tls.put('a', 2)
            self.assertEqual(2, tls.get('a'))

        thread = threading.Thread(target=another, args=())
        thread.start()
        thread.join()
        self.assertEqual(1, tls.get('a'))
        self.assertEqual(2, tls.get('a', thread=thread))