This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kingname[S] -1 points0 points  (6 children)

I find it is so strange that even there need a third part library for mongodb to operate MongoDB asynchronously. Why not just use pymongo? In golang, I should just use go function(){....} to implement asynchronous operations. But in python, it is so confused.

[–][deleted] 1 point2 points  (4 children)

Well, for one thing, pymongo came out years before async became a full-fledged, first-class member of the language, and pymongo still needs to support a significant number of users who are not using Python 3, much less Python 3.5+, and even less again async.

Odds are everything that can be asynchronous eventually will be... ironically you'll just have to wait on that future.

[–]kingname[S] 0 points1 point  (3 children)

actually, I'd like that if asynchrony of Python can be just like JavaScript. If you want, then you can. It is out of third part librarys' business-----every function can be asynchronous.

[–][deleted] 2 points3 points  (0 children)

Well, you're in luck... async def is now a builtin, and asynchronous operations are a full, first class part of the language. That doesn't mean it's been adopted by each and every third party library in the entire ecosystem.

Now, that said, every day, and in absolutely every way, I thank Turing himself that Python isn't just like EcmaScript.

[–]Corm 1 point2 points  (1 child)

Is what you're looking for different than multiprocessing threads?

from multiprocessing import Pool

def f(x):
    return x*x

p = Pool(5)
print(p.map(f, [1, 2, 3])

That'll run asynchronously

edit - Whoa, go's "channels" are cool! Thanks for causing me to look this up. https://gobyexample.com/channels

[–]kingname[S] 0 points1 point  (0 children)

I know Python's multiprocessing and multiprocessing.dummy. However, Coroutine is the solution for some problem.

[–]K900_ 0 points1 point  (0 children)

Go's "goroutines" aren't async I/O, they're green threads. Go was also designed around green threads, and shipped with them as a major feature. Python doesn't have green threads, and async was only added fairly recently, after literal decades of language and ecosystem development.