For people coming from JavaScript asynchronous programming is nothing new, but for python developers getting used to async functions and future (th...
For further actions, you may consider blocking this person and/or reporting abuse
This is so far the best and most informative article on async concurrency in python. Love it. Thanks a lot for posting online.
Hello and thanks for this great article.
Just one remark about multithreading though.
Each of Python threads will not execute line 2 at the same time. But something like this can happen:
thread 1 execute line 2 -> thread 2 execute line 2 -> thread 1 execute line 3 -> thread 2 execute line 3 !!! (size overflow)
Race condition.
Because of the GIL (Global Interpreter Lock) no line of Python can be executed at the same time when doing multithreading.
That's totally true. I didn't talk about it because it wasn't the main topic. Anyway on this subject you can use Processes instead of thread which don't suffer from GIL but i think they bring some overhead with them
I think this is somewhat unhelpful, what if I write mainly synchronous code and want some tasks to execute asynchronously? (I don't care about what the async function returns)
E.g I want to run a http request in the background every time something happens, but I don't want to create a thread, and run it
unfortunately, I think that what you are asking is not possible, if the program runs in a single process/thread it needs to know when to switch between tasks. I think for your problem the best solution is to use multiple threads which make the code really simple and you don't need to decide when to switch context with just minimal overhead.
On a related note: pythonclock.org/
cannot wait for it! I have a strong unmotivated hate for python2
I started using Python 2 around 2001, and had a very long laundry list of Things I Hate About Python.
When Python 3 came out, I had all but given up on Python. Took a look at Python 3, and out of my list of hate, everything-except-one-thing was fixed in Python 3.
The only thing that wasn't "fixed" was offside rule. I know offside rule is part of the heart and soul of Python. It will never change. Even after all this time, it still feels like fingernails on a chalkboard to me.
I can accept that one point of agree-to-disagree. (Heck, my Things I Hate About C++ list is about x1000 times longer than my Python 2 hate list. Python 3 with but a single hate item is bliss in comparison to C++!)
asycnio <- typo
fixed, thanks
which one?
sorry, i may have forgot to copy it from my website. This is the video, i will update the post as well
youtube.com/watch?v=M-UcUs7IMIM
I cannot see the link anymore, anyway I didn't talk about ensure_future to avoid creating confusion and so far I have never needed it.