{"id":6296,"date":"2023-01-04T00:48:03","date_gmt":"2023-01-04T00:48:03","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=6296"},"modified":"2023-06-03T12:34:21","modified_gmt":"2023-06-03T12:34:21","slug":"python-threading-event","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/python-concurrency\/python-threading-event\/","title":{"rendered":"Python Threading Event"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the Python threading Event object to communicate between threads.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-python-threading-event-object'>Introduction to the Python threading Event object <a href=\"#introduction-to-the-python-threading-event-object\" class=\"anchor\" id=\"introduction-to-the-python-threading-event-object\" title=\"Anchor for Introduction to the Python threading Event object\">#<\/a><\/h2>\n\n\n\n<p>Sometimes, you need to communicate between the <a href=\"https:\/\/www.pythontutorial.net\/python-concurrency\/python-threading\/\">threads<\/a>. To do that, you can use a <a href=\"https:\/\/www.pythontutorial.net\/python-concurrency\/python-threading-lock\/\">lock<\/a> (mutex) and a boolean variable.<\/p>\n\n\n\n<p>However, Python provides you with a better way to communicate between threads using the <code>Event<\/code> class from the <code>threading<\/code> module.<\/p>\n\n\n\n<p>The <code>Event<\/code> class offers a simple but effective way to coordinate between threads: one thread signals an event while other threads wait for it.<\/p>\n\n\n\n<p>The <code>Event<\/code> object wraps a boolean flag that can be set (<code>True<\/code>) or cleared (<code>False<\/code>). Multiple threads can wait for an <code>Event<\/code> to be set before proceeding or can reset the <code>Event<\/code> back to the cleared state.<\/p>\n\n\n\n<p>The following illustrates the steps for using the <code>Event<\/code> object:<\/p>\n\n\n\n<p>First, import the <code>Event<\/code> from the <code>threading<\/code> module:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> threading <span class=\"hljs-keyword\">import<\/span> Event<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Next, create a new <code>Event<\/code> object:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">event = Event()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>By default, the event is not set (cleared). The <code>is_set()<\/code> method of the event object will return <code>False<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">if<\/span> event.is_set():\n   <span class=\"hljs-comment\"># ...<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Then, set an event using the <code>set()<\/code> method: <\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">event.set()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Once an event is set, all the threads that wait on the event will be notified automatically.<\/p>\n\n\n\n<p>After that, unset an event via the <code>clear()<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">event.clear()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, threads can wait for the event to be set via the <code>wait()<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">event.wait()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>wait()<\/code> method blocks the execution of a thread until the event is set. In other words, the <code>wait()<\/code> method will block the current thread until another thread call the <code>set()<\/code> method to set the event.<\/p>\n\n\n\n<p>If an event is set, the <code>wait()<\/code> function returns immediately.<\/p>\n\n\n\n<p>To specify how long the thread is going to wait, you can use the timeout argument. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">event.wait(timeout=<span class=\"hljs-number\">5<\/span>) <span class=\"hljs-comment\"># wait for 5 seconds<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='python-threading-event-example'>Python threading event example <a href=\"#python-threading-event-example\" class=\"anchor\" id=\"python-threading-event-example\" title=\"Anchor for Python threading event example\">#<\/a><\/h2>\n\n\n\n<p>The following example shows a simple example of using the <code>Event<\/code> object to communicate between threads:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> threading <span class=\"hljs-keyword\">import<\/span> Thread, Event\n<span class=\"hljs-keyword\">from<\/span> time <span class=\"hljs-keyword\">import<\/span> sleep\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">task<\/span><span class=\"hljs-params\">(event: Event, id: int)<\/span> -&gt; <span class=\"hljs-keyword\">None<\/span>:<\/span>\n    print(<span class=\"hljs-string\">f'Thread <span class=\"hljs-subst\">{id}<\/span> started. Waiting for the signal....'<\/span>)\n    event.wait()\n    print(<span class=\"hljs-string\">f'Received signal. The thread <span class=\"hljs-subst\">{id}<\/span> was completed.'<\/span>)\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span> -&gt; <span class=\"hljs-keyword\">None<\/span>:<\/span>\n    event = Event()\n\n    t1 = Thread(target=task, args=(event,<span class=\"hljs-number\">1<\/span>))\n    t2 = Thread(target=task, args=(event,<span class=\"hljs-number\">2<\/span>))\n\n    t1.start()\n    t2.start()\n\n    print(<span class=\"hljs-string\">'Blocking the main thread for 3 seconds...'<\/span>)\n    sleep(<span class=\"hljs-number\">3<\/span>) \n    event.set()\n\n\n\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\n    main()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">Thread <span class=\"hljs-number\">1<\/span> started. Waiting <span class=\"hljs-keyword\">for<\/span> the signal....\nThread <span class=\"hljs-number\">2<\/span> started. Waiting <span class=\"hljs-keyword\">for<\/span> the signal....\nBlocking the main thread <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-number\">3<\/span> seconds...\nReceived signal. The thread <span class=\"hljs-number\">1<\/span> was completed.\nReceived signal. The thread <span class=\"hljs-number\">2<\/span> was completed.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How it works.<\/p>\n\n\n\n<p>First, define the <code>task()<\/code> function that accepts an <code>Event<\/code> object and an integer:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">task<\/span><span class=\"hljs-params\">(event: Event, id: int)<\/span> -&gt; <span class=\"hljs-keyword\">None<\/span>:<\/span>\n    print(<span class=\"hljs-string\">f'Thread <span class=\"hljs-subst\">{id}<\/span> started. Wait for the signal....'<\/span>)\n    event.wait()\n    print(<span class=\"hljs-string\">f'Receive signal. The thread <span class=\"hljs-subst\">{id}<\/span> was completed.'<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Inside, the <code>task()<\/code> function, we call the <code>wait()<\/code> method of the event object to wait for the event to be set by the main thread.<\/p>\n\n\n\n<p>Second, create an <code>Event<\/code> object inside the <code>main()<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">event = Event()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, create two child threads that execute the <code>task()<\/code> function with the same event object and different id 1 and 2:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">t1 = Thread(target=task, args=(event,<span class=\"hljs-number\">1<\/span>))\nt2 = Thread(target=task, args=(event,<span class=\"hljs-number\">2<\/span>))<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fourth, start both threads by calling the <code>start()<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">t1.start()\nt2.start()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fifth, call the <code>sleep()<\/code> method to block the main thread for three seconds:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">sleep(<span class=\"hljs-number\">3<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Since the <code>task()<\/code> function call the <code>wait()<\/code> method of the event object, both <code>t1<\/code> and <code>t2<\/code> threads will wait for the event to be set before continuing.<\/p>\n\n\n\n<p>Finally, set the event by calling the <code>set()<\/code> method from the main thread:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">event.set()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Both <code>t1<\/code> and <code>t2<\/code> threads will be notified and continue executing until the end.<\/p>\n\n\n\n<p>Note that you&#8217;ll learn how to use the Event object to <a href=\"https:\/\/www.pythontutorial.net\/python-concurrency\/python-stop-thread\/\">stop a child thread<\/a> from the main thread in the next tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='practical-example-of-using-threading-event'>Practical example of using Threading event <a href=\"#practical-example-of-using-threading-event\" class=\"anchor\" id=\"practical-example-of-using-threading-event\" title=\"Anchor for Practical example of using Threading event\">#<\/a><\/h2>\n\n\n\n<p>The following example illustrates hwo to use the threading event to synchronize between two threads:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Thread #1 downloads a text file from URL <code>https:\/\/www.ietf.org\/rfc\/rfc793.txt<\/code>, once completed, it notifies the second thread to count the words from the downloaded text file.<\/li>\n\n\n\n<li>Thread #2 starts and wait for the completed signal from the thread #1. Once, receiving the signal, it starts counting the words from the downloaded file.<\/li>\n<\/ul>\n\n\n\n<p>Here&#8217;s the complete program:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">from threading import Thread, Event\r\nfrom urllib import request\r\n\r\n\r\ndef download_file(url, event):\r\n    <span class=\"hljs-comment\"># Download the file form URL<\/span>\r\n    <span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Downloading file from {url}...\"<\/span>)\r\n    filename, _ = request.urlretrieve(url, <span class=\"hljs-string\">\"rfc793.txt\"<\/span>)\r\n\r\n    <span class=\"hljs-comment\"># File download completed, set the event<\/span>\r\n    event.set()\r\n\r\n\r\ndef process_file(event):\r\n    <span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Waiting for the file to be downloaded...\"<\/span>)\r\n    event.wait()  <span class=\"hljs-comment\"># Wait for the event to be set<\/span>\r\n\r\n    <span class=\"hljs-comment\"># File has been downloaded, start processing it<\/span>\r\n    <span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"File download completed. Starting file processing...\"<\/span>)\r\n\r\n    <span class=\"hljs-comment\"># Count the number of words in the file<\/span>\r\n    word_count = <span class=\"hljs-number\">0<\/span>\r\n    with open(<span class=\"hljs-string\">\"rfc793.txt\"<\/span>, <span class=\"hljs-string\">\"r\"<\/span>) <span class=\"hljs-keyword\">as<\/span> file:\r\n        <span class=\"hljs-keyword\">for<\/span> line in file:\r\n            words = line.split()\r\n            word_count += len(words)\r\n\r\n    <span class=\"hljs-comment\"># Print the word count<\/span>\r\n    <span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">\"Number of words in the file: {word_count}\"<\/span>)\r\n\r\n\r\ndef main():\r\n    <span class=\"hljs-comment\"># Create an Event object<\/span>\r\n    event = Event()\r\n\r\n    <span class=\"hljs-comment\"># Create and start the file download thread<\/span>\r\n    download_thread = Thread(target=download_file, \r\n                             args=(<span class=\"hljs-string\">\"https:\/\/www.ietf.org\/rfc\/rfc793.txt\"<\/span>,  event))\r\n\r\n    download_thread.start()\r\n\r\n    <span class=\"hljs-comment\"># Create and start the file processing thread<\/span>\r\n    process_thread = Thread(target=process_file, args=(event,))\r\n    process_thread.start()\r\n\r\n    <span class=\"hljs-comment\"># Wait for both threads to complete<\/span>\r\n    download_thread.join()\r\n    process_thread.join()\r\n\r\n    <span class=\"hljs-keyword\">print<\/span>(<span class=\"hljs-string\">\"Main thread finished.\"<\/span>)\r\n\r\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>    :\r\n    main()\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code>threading.Event<\/code> class to communicate between threads.<\/li>\n\n\n\n<li>Use the <code>set()<\/code> method to set the event and <code>clear()<\/code> method to unset the event.<\/li>\n\n\n\n<li>Use the <code>is_set()<\/code> method to check if an event is set.<\/li>\n\n\n\n<li>Use the <code>wait()<\/code> method to wait for the event to be set.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"6296\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-concurrency\/python-threading-event\/\"\n\t\t\t\tdata-post-title=\"Python Threading Event\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"6296\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-concurrency\/python-threading-event\/\"\n\t\t\t\tdata-post-title=\"Python Threading Event\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to use the Python threading Event object to communicate between threads.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":4104,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6296","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/6296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=6296"}],"version-history":[{"count":0,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/6296\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/4104"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=6296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}