小编Arc*_*nan的帖子

如何停止在执行程序中运行的循环?

我正在运行需要时间才能完成的功能。用户可以选择停止此功能/事件。有没有简单的方法来停止线程或循环?

class ThreadsGenerator:
    MAX_WORKERS = 5

    def __init__(self):
        self._executor = ThreadPoolExecutor(max_workers=self.MAX_WORKERS)
        self.loop = None
        self.future = None

    def execute_function(self, function_to_execute, *args):
        self.loop = asyncio.get_event_loop()
        self.future = self.loop.run_in_executor(self._executor, function_to_execute, *args)

        return self.future
Run Code Online (Sandbox Code Playgroud)

我想在用户单击停止按钮时尽快停止该功能,而不是等待完成其工作。

提前致谢!

python multithreading python-3.x python-asyncio concurrent.futures

2
推荐指数
1
解决办法
1261
查看次数

list = []与list.clear()之间的区别

list = []和之间有什么区别list.clear()

根据代码的行为和我自己的观察,list.clear()删除其条目以及用于添加其数据的条目。

例:

container.append(list)
list.clear()
Run Code Online (Sandbox Code Playgroud)

container 也将是 []

python list python-3.x

2
推荐指数
1
解决办法
247
查看次数