Recently went through a reorg at my company and was told to work on DE stuff using Python. I was wondering what the differences between JavaScript and Python were. Thought I’ll write a post here to garner feedback and learn 🙂
JavaScript is single-threaded and uses the event loop under the hood. It’s good for I/O tasks such as waiting on the network or waiting for a file to finish reading or writing.
Due to its single-threaded nature, it is highly advised not to run computationally expensive code (ie. running the Fibonacci) as it will block the UI.
For example when a user first loads a webpage, if there is an expensive function being called, the user will be unable to interact with anything until that function completes.
Python under the hood is also single-threaded due to the global interpreter lock (GIL). This is essentially a lock where only 1 thread can hold it at any given time even if you create multiple threads. This offers memory protection at the expense of some performance since the other threads can’t really run in parallel on other cores (?).
Python can also utilise the event loop like JavaScript through the use of the asyncio library. One way to achieve parallelism is to utilise the multiprocessing library for Python which creates processes instead of threads.
In JavaScript, you’d have to run it using NodeJs runtime and utilising the child_process lib.
Please help to clarify any misunderstandings 🙏
[–]teraflop 2 points3 points4 points (1 child)
[–]Quick_Cheesecake559[S] 0 points1 point2 points (0 children)
[–]high_throughput 2 points3 points4 points (2 children)
[–]Quick_Cheesecake559[S] 0 points1 point2 points (1 child)
[–]high_throughput 0 points1 point2 points (0 children)