<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hasan Sajedi</title>
    <description>The latest articles on DEV Community by Hasan Sajedi (@hasansajedi).</description>
    <link>https://dev.to/hasansajedi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F93898%2F30f1fe99-1459-4d2f-acd1-aec8cfd27ea9.jpeg</url>
      <title>DEV Community: Hasan Sajedi</title>
      <link>https://dev.to/hasansajedi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hasansajedi"/>
    <language>en</language>
    <item>
      <title>Monkey Patching in Python</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Sat, 16 Feb 2019 11:47:14 +0000</pubDate>
      <link>https://dev.to/hasansajedi/monkey-patching-in-python-1apk</link>
      <guid>https://dev.to/hasansajedi/monkey-patching-in-python-1apk</guid>
      <description>&lt;p&gt;In Python, the term monkey patch refers to dynamic (or run-time) modifications of a class or module. In Python, we can actually change the behavior of code at run-time.&lt;/p&gt;

&lt;h1&gt;
  
  
  monk.py
&lt;/h1&gt;

&lt;p&gt;class A: &lt;br&gt;
     def func(self): &lt;br&gt;
          print "func() is being called"&lt;/p&gt;

&lt;p&gt;We use above module (monk) in below code and change behavior of func() at run-time by assigning different value.&lt;/p&gt;

&lt;p&gt;import monk &lt;br&gt;
def monkey_f(self): &lt;br&gt;
     print "monkey_f() is being called"&lt;/p&gt;

&lt;h1&gt;
  
  
  replacing address of "func" with "monkey_f"
&lt;/h1&gt;

&lt;p&gt;monk.A.func = monkey_f &lt;br&gt;
obj = monk.A() &lt;/p&gt;

&lt;h1&gt;
  
  
  calling function "func" whose address got replaced
&lt;/h1&gt;

&lt;h1&gt;
  
  
  with function "monkey_f()"
&lt;/h1&gt;

&lt;p&gt;obj.func() &lt;/p&gt;

&lt;p&gt;Output :monkey_f() is being called&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>What is the difference between business intelligence, simulation and data mining? </title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Wed, 19 Dec 2018 20:24:25 +0000</pubDate>
      <link>https://dev.to/hasansajedi/what-is-the-difference-between-business-intelligence-simulation-and-data-mining--2l40</link>
      <guid>https://dev.to/hasansajedi/what-is-the-difference-between-business-intelligence-simulation-and-data-mining--2l40</guid>
      <description>&lt;p&gt;Created by Hasan Sajedi.&lt;br&gt;
&lt;a href="https://link.medium.com/OFaNiMADMS"&gt;https://link.medium.com/OFaNiMADMS&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Develop Fraud detection with python</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Wed, 24 Oct 2018 09:57:38 +0000</pubDate>
      <link>https://dev.to/hasansajedi/develop-fraud-detection-with-python-2i4e</link>
      <guid>https://dev.to/hasansajedi/develop-fraud-detection-with-python-2i4e</guid>
      <description>

&lt;p&gt;What is Fraud?&lt;/p&gt;

&lt;p&gt;In law, fraud is deliberate deception to secure unfair or unlawful gain, or to deprive a victim of a legal right. Fraud itself can be a civil wrong (i.e., a fraud victim may sue the fraud perpetrator to avoid the fraud or recover monetary compensation), a criminal wrong (i.e., a fraud perpetrator may be prosecuted and imprisoned by governmental authorities), or it may cause no loss of money, property or legal right but still be an element of another civil or criminal wrong. The purpose of fraud may be monetary gain or other benefits, such as obtaining a passport or travel document, driver’s license or qualifying for a mortgage by way of false statements.&lt;/p&gt;

&lt;p&gt;For more info read below link:&lt;br&gt;
&lt;a href="https://medium.com/sajedi/develop-fraud-detection-with-python-4b6968ccf678"&gt;https://medium.com/sajedi/develop-fraud-detection-with-python-4b6968ccf678&lt;/a&gt;&lt;/p&gt;


</description>
      <category>datascience</category>
      <category>python</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>911 Calls Capstone Project (Using Python — numpy, pandas, matplotlib and seaborn)</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Sun, 30 Sep 2018 06:55:06 +0000</pubDate>
      <link>https://dev.to/hasansajedi/911-calls-capstone-project-using-pythonnumpy-pandas-matplotlib-and-seaborn-2fae</link>
      <guid>https://dev.to/hasansajedi/911-calls-capstone-project-using-pythonnumpy-pandas-matplotlib-and-seaborn-2fae</guid>
      <description>&lt;p&gt;&lt;a href="https://medium.com/@hassansajedi/911-calls-capstone-project-using-python-numpy-pandas-matplotlib-and-seaborn-86b26100e611"&gt;https://medium.com/@hassansajedi/911-calls-capstone-project-using-python-numpy-pandas-matplotlib-and-seaborn-86b26100e611&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascince</category>
      <category>numpy</category>
      <category>pandas</category>
    </item>
    <item>
      <title>8 Steps to run Data Science project</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Sun, 09 Sep 2018 09:23:43 +0000</pubDate>
      <link>https://dev.to/hasansajedi/8-steps-to-run-data-science-project-om8</link>
      <guid>https://dev.to/hasansajedi/8-steps-to-run-data-science-project-om8</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;We will follow the general machine learning workflow step-by-step:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Problem Definition&lt;/li&gt;
&lt;li&gt;Data cleaning and formatting&lt;/li&gt;
&lt;li&gt;Exploratory data analysis&lt;/li&gt;
&lt;li&gt;Feature engineering and selection&lt;/li&gt;
&lt;li&gt;Compare several machine learning models on a performance metric&lt;/li&gt;
&lt;li&gt;Perform hyperparameter tuning on the best model&lt;/li&gt;
&lt;li&gt;Evaluate the best model on the testing set&lt;/li&gt;
&lt;li&gt;Interpret the model results&lt;/li&gt;
&lt;li&gt;Draw conclusions and document work&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>(sapass) With this module you can easy generate password in python projects</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Sun, 26 Aug 2018 13:08:42 +0000</pubDate>
      <link>https://dev.to/hasansajedi/sapass-with-this-module-you-can-easy-generate-password-in-python-projects-5b5g</link>
      <guid>https://dev.to/hasansajedi/sapass-with-this-module-you-can-easy-generate-password-in-python-projects-5b5g</guid>
      <description>&lt;p&gt;sapass&lt;br&gt;
First version of password generator for python projects&lt;/p&gt;

&lt;p&gt;Install easy&lt;/p&gt;

&lt;p&gt;Use Easy&lt;/p&gt;

&lt;p&gt;Use python version &amp;gt;= 2.7&lt;/p&gt;

&lt;p&gt;Please visit below link:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pypi.org/project/sapass/"&gt;https://pypi.org/project/sapass/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>password</category>
      <category>pypi</category>
    </item>
    <item>
      <title>How to use Queue in Python</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Thu, 23 Aug 2018 21:23:34 +0000</pubDate>
      <link>https://dev.to/hasansajedi/how-to-use-queue-in-python-15mp</link>
      <guid>https://dev.to/hasansajedi/how-to-use-queue-in-python-15mp</guid>
      <description>&lt;p&gt;This Article will help you to understand a Queue data structure and how to implement it.&lt;/p&gt;

&lt;p&gt;A Queue is a simple data structure concept that can be easily applied in our day to day life, like when you stand in a line to buy coffee at Starbucks.&lt;br&gt;
Let's make a few observations based on this example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0x1l1l0t3qxuv1hn37wm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F0x1l1l0t3qxuv1hn37wm.png" alt="Queue"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Now, let’s look at the above points programmatically:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Queues are open from both ends meaning elements are added from the back and removed from the front&lt;/li&gt;
&lt;li&gt;The element to be added first is removed first (First In First Out - FIFO)
If all the elements are removed, then the queue is empty and if you try to remove elements from an empty queue, a warning or an error message is thrown.&lt;/li&gt;
&lt;li&gt;If the queue is full and you add more elements to the queue, a warning or error message must be thrown.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Algorithm
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Declare a list and an integer MaxSize, denoting a virtual maximum size of the Queue&lt;/li&gt;
&lt;li&gt;Head and Tail are initially set to 0&lt;/li&gt;
&lt;li&gt;Size method

&lt;ul&gt;
&lt;li&gt;Calculates the number of elements in the queue -&amp;gt; Size = Tail - Head&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Reset method:

&lt;ul&gt;
&lt;li&gt;Resets Tail and Head to 0&lt;/li&gt;
&lt;li&gt;Creates a new Queue (initializes queue to a new list)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Enqueue operation:

&lt;ul&gt;
&lt;li&gt;Check if Size is less than the MaxSize:

&lt;ul&gt;
&lt;li&gt;If yes, append data to Queue and then increment Tail by 1&lt;/li&gt;
&lt;li&gt;If no, print Queue full message&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Dequeue operation:

&lt;ul&gt;
&lt;li&gt;Check if Size is greater than 0:

&lt;ul&gt;
&lt;li&gt;If yes, pop the first element from the list and increment Head by 1&lt;/li&gt;
&lt;li&gt;If no:

&lt;ul&gt;
&lt;li&gt;Call Reset method&lt;/li&gt;
&lt;li&gt;Print Queue empty message
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

    &lt;span class="c1"&gt;#Constructor
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="c1"&gt;#Adding elements
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;#Checking if the queue is full
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Queue Full&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;     

    &lt;span class="c1"&gt;#Deleting elements 
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;#Checking if the queue is empty
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resetQueue&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="nf"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Queue Empty&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
        &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;

    &lt;span class="c1"&gt;#Calculate size
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;

    &lt;span class="c1"&gt;#Reset queue
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;resetQueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints Queue Full!
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 8        
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 8
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 7 
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 6
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 5
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 4
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 3
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 2
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints 1
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dequeue&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#prints Queue Empty
#Queue is reset here 
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enqueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="c1"&gt;#prints True
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: Element 9 was not added to the Queue and hence the size of the Queue remains 8&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>python</category>
      <category>queue</category>
    </item>
    <item>
      <title>Display calendar with python</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Wed, 22 Aug 2018 06:56:51 +0000</pubDate>
      <link>https://dev.to/hasansajedi/display-calendar-with-python-56pd</link>
      <guid>https://dev.to/hasansajedi/display-calendar-with-python-56pd</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Python has a built-in function, 'calendar' to work with date related tasks. &lt;br&gt;
You will learn to display the calendar of a given date with below example.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;calendar&lt;/span&gt;

&lt;span class="n"&gt;yy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2018&lt;/span&gt;
&lt;span class="n"&gt;mm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;calendar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;yy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mm&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the program top, we import the calendar module. The built-in function month() inside the module takes in the year and the month and displays the calendar for that month of the year.&lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    August 2018
Mo Tu We Th Fr Sa Su
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
      <category>calendar</category>
    </item>
    <item>
      <title>Distributed and Parallel Computing with/for Python</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Mon, 20 Aug 2018 16:59:01 +0000</pubDate>
      <link>https://dev.to/hasansajedi/distributed-and-parallel-computing-withfor-python-2f19</link>
      <guid>https://dev.to/hasansajedi/distributed-and-parallel-computing-withfor-python-2f19</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;dispy is a comprehensive, yet easy to use framework for creating and using compute clusters to execute computations in parallel across multiple processors in a single machine (SMP), among many machines in a cluster, grid or cloud. &lt;br&gt;
dispy is well suited for data parallel (SIMD) paradigm where a computation (Python function or standalone program) is evaluated with different (large) datasets independently with no communication among computation tasks (except for computation tasks sending Provisional/Intermediate Results or Transferring Files to the client). &lt;br&gt;
If communication/cooperation among tasks is needed, Distributed Communicating Processes module of pycos framework could be used.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Some of the features of dispy:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;dispy is implemented with pycos, an independent framework for asynchronous, concurrent, distributed, network programming with tasks (without threads). pycos uses non-blocking sockets with I/O notification mechanisms epoll, kqueue, poll and Windows I/O Completion Ports (IOCP) for high performance and scalability, so dispy works efficiently with a single node or large cluster(s) of nodes - one user reported using dispy with 500 nodes in Google cloud platform. pycos itself has support for distributed/parallel computing, including transferring computations, files etc., and message passing (for communicating with client and other computation tasks). While dispy can be used to schedule jobs of a computation to get the results, pycos can be used to create distributed communicating processes, for broad range of use cases, including in-memory processing, data streaming, real-time (live) analytics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Computations (Python functions or standalone programs) and their dependencies (files, Python functions, classes, modules) are distributed to nodes automatically. Computations, if they are Python functions, can also transfer files on the nodes to the client.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Computation nodes can be anywhere on the network (local or remote). For security, either simple hash based authentication or SSL encryption can be used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After each execution is finished, the results of execution, output, errors and exception trace are made available for further processing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In-memory processing is supported (with some limitations under Windows); i.e., computations can work on data in memory instead of loading data from files each time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Nodes may become available dynamically: dispy will schedule jobs whenever a node is available and computations can use that node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Job and cluster status notification mechanisms allow for asynchronous processing of job results, customized job schedulers etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Client-side and server-side fault recovery are supported:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If user program (client) terminates unexpectedly (e.g., due to uncaught exception), the nodes continue to execute scheduled jobs. The results of the scheduled (but unfinished at the time of crash) jobs for that cluster can be retrieved easily with (Fault) Recover Jobs.&lt;/p&gt;

&lt;p&gt;If a computation is marked reentrant when a cluster is created and a node (server) executing jobs for that computation fails, dispy automatically resubmits those jobs to other available nodes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;dispy can be used in a single process to use all the nodes exclusively (with JobCluster) or in multiple processes simultaneously sharing the nodes (with SharedJobCluster and &lt;a href="http://dispy.sourceforge.net/dispyscheduler.html"&gt;dispyscheduler (Shared Execution program)&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://dispy.sourceforge.net/httpd.html"&gt;Monitor and Manage Cluster&lt;/a&gt; with a web browser, including in iOS or Android devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setup private compute infrastructure with existing hardware (the only requirements are that computers are connected and have Python installed), or use external cloud computing services (users reported using dispy with Amazon EC2, Google Cloud and Microsoft Azure), either exclusively or in addition to any local compute nodes. See &lt;a href="http://dispy.sourceforge.net/dispy.html#cloud"&gt;Cloud Computing&lt;/a&gt; for details.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;dispy works with Python versions 2.7+ and 3.1+ and tested on Linux, OS X and Windows; it may work on other platforms too. dispy works with JIT interpreter &lt;a href="http://pypy.org/"&gt;PyPy&lt;/a&gt; as well.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://dispy.sourceforge.net/"&gt;Reference&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>dispy</category>
      <category>distributed</category>
      <category>parallel</category>
    </item>
    <item>
      <title>Running a method as a background process in Python</title>
      <dc:creator>Hasan Sajedi</dc:creator>
      <pubDate>Mon, 20 Aug 2018 16:31:41 +0000</pubDate>
      <link>https://dev.to/hasansajedi/running-a-method-as-a-background-process-in-python-21li</link>
      <guid>https://dev.to/hasansajedi/running-a-method-as-a-background-process-in-python-21li</guid>
      <description>

&lt;p&gt;Below a little code snippet for running class methods as background threads in Python. The run() method does some work forever and in this use case you want it to do that in the background. while the rest of the application continues it’s work.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;threading&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TestThreading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;object&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt;

        &lt;span class="n"&gt;thread&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="n"&gt;thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;daemon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
        &lt;span class="n"&gt;thread&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c"&gt;# More statements comes here&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;' : Start task in the background'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;interval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;tr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;TestThreading&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;' : First output'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;' : Second output'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;Below is Output:&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;2018-08-18 13:39:59.021000 : Start task in the background&lt;br&gt;
2018-08-18 13:40:00.036000 : First output&lt;br&gt;
2018-08-18 13:40:00.036000 : Start task in the background&lt;br&gt;
2018-08-18 13:40:01.036000 : Start task in the background&lt;br&gt;
2018-08-18 13:40:02.036000 : Second output&lt;/p&gt;
&lt;/blockquote&gt;


</description>
      <category>python</category>
      <category>thread</category>
      <category>multithreading</category>
    </item>
  </channel>
</rss>
