<?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: Hassan Tahir</title>
    <description>The latest articles on DEV Community by Hassan Tahir (@thehassantahir).</description>
    <link>https://dev.to/thehassantahir</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%2F784109%2Fb47608c1-4c26-4e0e-98e5-5737da9dbc73.jpg</url>
      <title>DEV Community: Hassan Tahir</title>
      <link>https://dev.to/thehassantahir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thehassantahir"/>
    <language>en</language>
    <item>
      <title>Deadlock in Python</title>
      <dc:creator>Hassan Tahir</dc:creator>
      <pubDate>Mon, 06 Jun 2022 10:36:30 +0000</pubDate>
      <link>https://dev.to/thehassantahir/deadlock-in-python-44jh</link>
      <guid>https://dev.to/thehassantahir/deadlock-in-python-44jh</guid>
      <description>&lt;p&gt;In the field of computer science, deadlock refers to a specific situation at a time planning, when no progress can be made and the system is locked in it current situation. In many cases, the condition is caused by a lack of, or mistreatment, communication between different locking devices (for thread synchronization purposes).&lt;br&gt;
Deadlock is also defined by the conditions that the corresponding system must have at the same time for a deadlock. These issues were first raised by the media computer scientist Edward G. Coffman, Jr., and as a result became known as the Coffman conditions. &lt;/p&gt;

&lt;p&gt;Let's take a quick look at a basic example of deadlock. Consider the same program in&lt;br&gt;
which are two different processes (process A and process B), and two different processes&lt;br&gt;
resources (R1 service and R2 service), as follows:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzhmawpvigslly3fq7ak.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzhmawpvigslly3fq7ak.png" alt="deadlock sample"&gt;&lt;/a&gt;&lt;br&gt;
There are no resources that can be assigned to all the different processes, and each process needs to be done access both resources to use its instructions. Take procedure A, for example. It already exists holding a R1 service, but it also requires R2 to continue its operation. However, R2 cannot be detected by process A, as it is detected by process B. Thus, process A cannot go on. It is the same with process B, which holds R2 and requires R1 to continue. R1 says,on the other hand, managed by process A. &lt;/p&gt;
&lt;h2&gt;
  
  
  Python Preceding in Deadlock Situation
&lt;/h2&gt;

&lt;p&gt;we will use the preceding situation in the actual Python application.Specifically, we will have two locks (we will call them Lock A and lock B), and two are separate strands connecting the locks (string A and string B). In our program, we will establish a situation where string A gets the A lock and waits to get the B lock, which it has already been secured with string B, that is, waiting for lock A.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import threading
import time
 def thread_a():
     print('Thread A is starting...') 
     print('Thread A waiting to acquire lock A.')
     lock_a.acquire()
     print('Thread A has acquired lock A, performing some calculation...')

time.sleep(2)
     print('Thread A waiting to acquire lock B.')
     lock_b.acquire()
     print('Thread A has acquired lock B, performing some calculation...')
     time.sleep(2)
     print('Thread A releasing both locks.')
     lock_a.release()
     lock_b.release()
 def thread_b():
     print('Thread B is starting...')
     print('Thread B waiting to acquire lock B.')
     lock_b.acquire()
     print('Thread B has acquired lock B, performing some calculation...')
     time.sleep(5)
     print('Thread B waiting to acquire lock A.')
     lock_a.acquire()
     print('Thread B has acquired lock A, performing some calculation...')
     time.sleep(5)
     print('Thread B releasing both locks.')
 lock_b.release()
 lock_a.release()
 lock_a = threading.Lock()
 lock_b = threading.Lock()

 thread1 = threading.Thread(target=thread_a)
 thread2 = threading.Thread(target=thread_b)
 thread1.start()
 thread2.start()
 thread1.join()
 thread2.join()

 print('Finished.')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, the functions of thread_a () and thread_b () specify our thread A and thread B, respectively. In our main program, we also have two addictive items.Lock: lock A and lock B.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note that we use the time.sleep () function to mimic the action of others calculated statistics.&lt;/em&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvjob79s3a35vufaqhlhz.jpeg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvjob79s3a35vufaqhlhz.jpeg" alt="deadlock lizard"&gt;&lt;/a&gt;&lt;br&gt;
First, we start both cable A and cable B at about the same time, inside the main system. With the suspension of the string command in mind, we can see that in at this point, both threads will be started; string A will try to get the lock A, and it will successfully do so, as lock A is currently available. The same goes for series B then lock B. The two strands will then proceed to perform the calculations themselves.&lt;/p&gt;

&lt;p&gt;Let's consider the current state of our system: Lock A is obtained by string A, too Lock B is obtained by string B. After their various calculation procedures complete, series A will then try to find the B key, and string B will try to find the A key.&lt;/p&gt;

&lt;p&gt;We can easily see that this is the beginning of our deadlock situation: as lock B already exists held by string B, and cannot be obtained by rope A, string B, for the same reason,&lt;br&gt;
can't find key A.&lt;br&gt;
Both wires will now wait permanently, to get their second lock.&lt;/p&gt;

&lt;p&gt;However, the only way the lock can be released is for the cord to continue its operation instructions and release all the locks it has at the end. So our plan will be is stuck in its current operation, and no further progress will be made.&lt;/p&gt;

&lt;p&gt;to be continued.. .&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Algorithms &lt;a href="https://github.com/thehassantahir/Python-Algos" rel="noopener noreferrer"&gt;Detailed Python Algorithms&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github &lt;a href="https://github.com/thehassantahir" rel="noopener noreferrer"&gt;Thehassantahir&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Share + Comment + Like&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>python</category>
    </item>
    <item>
      <title>Is it worth to learn Python in 2022?</title>
      <dc:creator>Hassan Tahir</dc:creator>
      <pubDate>Wed, 12 Jan 2022 18:55:19 +0000</pubDate>
      <link>https://dev.to/thehassantahir/is-it-worth-to-learn-python-in-2022-18p1</link>
      <guid>https://dev.to/thehassantahir/is-it-worth-to-learn-python-in-2022-18p1</guid>
      <description>&lt;p&gt;Python has gained a massive amount of attention in the past 5 years. Anyone who is related to the development industry hears the word Python (the first thing that jumps in mind is programming language) instead of a snake. We are in 2022 and we should change the working trends and patterns we were following in the previous year 2021, Why? It helps to innovate and make the mind more productive. This is the reason every year we got 60k search count on python programming language, &lt;strong&gt;is python worth learning in 2022?&lt;/strong&gt; (w.r.t years)&lt;/p&gt;

&lt;p&gt;Here is why you should or should not learn python this year! &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1&lt;/strong&gt;. Python is a beginner friendly language. It is very simple to understand. Any non tech can learn this language.&lt;br&gt;
&lt;strong&gt;2&lt;/strong&gt;. According to 2021 development market python developers are taking high salaries from 72,000$ - 1,44,000$ per year as comparing with other developers.&lt;br&gt;
&lt;strong&gt;3&lt;/strong&gt;. Python is very popular because of it’s multi-platform integration as well as with other major and minor programming languages.&lt;br&gt;
&lt;strong&gt;4&lt;/strong&gt;. Thousands of Multinational companies and organizations are using python such as Uber, NASA, Instagram, NSA and many more.&lt;br&gt;
&lt;strong&gt;5&lt;/strong&gt;. Python is &lt;a href="https://github.com/python"&gt;open-source&lt;/a&gt; so it has the most powerful and massive frameworks and libraries which are more secure and faster than most of the other languages. Such as, Pandas &amp;amp; Numpy for Data Science and Deep Machine learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Cons&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1&lt;/strong&gt;. Lack of logic in design programs.&lt;br&gt;
&lt;strong&gt;2&lt;/strong&gt;. Slightly slower than other major languages.&lt;br&gt;
&lt;strong&gt;3&lt;/strong&gt;. Python programs do not compile before execution instead under development you have to run it each time.&lt;/p&gt;

&lt;p&gt;As we can see Python don't have any major issues for not eligible to be learned in 2022. I personally suggest every beginner to start learn Python as your basic machine language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Comment your views &amp;amp;&lt;br&gt;
Follow me on &lt;a href="https://github.com/thehassantahir"&gt;Github&lt;/a&gt; &amp;amp; &lt;a href="https://twitter.com/thehassantahir"&gt;Twitter&lt;/a&gt; and Sponsor me on&lt;/em&gt;&lt;/strong&gt; 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.patreon.com/hassantahir"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lP059cim--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n16ri16f50t2xf348879.png" alt="Patreon Image" width="340" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>target="_blank" is a security risk?</title>
      <dc:creator>Hassan Tahir</dc:creator>
      <pubDate>Sat, 01 Jan 2022 17:58:17 +0000</pubDate>
      <link>https://dev.to/thehassantahir/targetblank-is-a-security-risk-1ee4</link>
      <guid>https://dev.to/thehassantahir/targetblank-is-a-security-risk-1ee4</guid>
      <description>&lt;p&gt;As we all use target="_blank" to open the link into new tab of a window but everyone should know a risk inside it.&lt;/p&gt;

&lt;p&gt;When we open a new tab link &lt;code&gt;window.opener&lt;/code&gt; get triggered which made a limited access to the specific tab opened, &lt;em&gt;for example&lt;/em&gt;; you can not go back in the previous page by clicking back button from your URL bar.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So what is the risk here?&lt;/strong&gt;&lt;br&gt;
when the new tab link open it can alter the Link page URL from &lt;code&gt;window.opener.location&lt;/code&gt;. &lt;br&gt;
If your external link is not trusty that may cause a real problem to your website.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What can happen?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hacker can redirect your domain.&lt;/li&gt;
&lt;li&gt;CSRF can be performed.&lt;/li&gt;
&lt;li&gt;XML entities can be altered. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to prevent this?&lt;/strong&gt;&lt;br&gt;
Do not forget to add relation attribute in your link tag &lt;code&gt;rel=noopener noreferrer&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In a Nutshell&lt;/em&gt;&lt;/strong&gt; &lt;code&gt;&amp;lt;a href="https://thehassantahir.web.app" target="_blank" rel="noopener noreferrer"&amp;gt;Thehassantahir&amp;lt;/a&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Comment your views &amp;amp;&lt;br&gt;
Follow me on &lt;a href="https://github.com/thehassantahir" rel="noopener noreferrer"&gt;Github&lt;/a&gt; &amp;amp; &lt;a href="https://twitter.com/thehassantahir" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and Sponsor me on&lt;/em&gt;&lt;/strong&gt; 👇&lt;br&gt;
&lt;a href="https://www.patreon.com/hassantahir" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn16ri16f50t2xf348879.png" alt="Patreon Image"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>html</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
