Terminate multiple threads when any thread completes a task

前端 未结 5 818
囚心锁ツ
囚心锁ツ 2020-11-30 19:33

I am new to both python, and to threads. I have written python code which acts as a web crawler and searches sites for a specific keyword. My question is, how can I use thre

5条回答
  •  遥遥无期
    2020-11-30 20:07

    First off, if you're new to python, I wouldn't recommend facing threads yet. Get used to the language, then tackle multi-threading.

    With that said, if your goal is to parallelize (you said "run at the same time"), you should know that in python (or at least in the default implementation, CPython) multiple threads WILL NOT truly run in parallel, even if multiple processor cores are available. Read up on the GIL (Global Interpreter Lock) for more information.

    Finally, if you still want to go on, check the Python documentation for the threading module. I'd say Python's docs are as good as references get, with plenty of examples and explanations.

提交回复
热议问题