24,628 karma · joined Oct 21, 2019 (7y ago) · 5,512 submissions
https://www.bitecode.dev/
Email: contact at bitecode.dev
comment 5y ago · link · parent
E.G: I used to "spray my files in the home dir" for my apps, until I discovered "appdirs" (https://pypi.org/project/appdirs/1.4.0/). Once I had an easy way to always has a clean and correct path for my app config/data/tmp file, I just used it.
comment 5y ago · link · parent
comment 5y ago · link · parent
- you can replace builtins in python. - you have __dunder__ methods and multiple inheritance. - JS has an ever running event loop and is async by default. - python is more strickly typed.
It's not impossible (see brython), but it's not easy either.
comment 5y ago · link · parent
Pyodine => the cpython implementation, but compiled to wasm. It's very heavy (10Mo), but it brings the real, whole cpython implementation in the browser so it will behave the same and have the entire stdlib. It also comes with optional NumPy, Matplotlib, pandas, SciPy, and scikit-learn. Use it if you want people to write python in the browser, but don't want to expose your server to their code.
comment 5y ago · link · parent
GTA uses some surrealist contrasts because it makes the games easier to play, especially for long hours, or when you go fast.
But the tech is so new I'm not going to complain, it's already very good, especially given what it eats in resources.
comment 5y ago · link · parent
That's why practicality beats purity in the vast majority of situations.
There is a place for purity, but you need a hell of a setup.
comment 5y ago · link · parent
Not to mention python runs on constraints systems such as MicroPython, which features coroutines.
HN, the place were people complain about how electron is bloated then ask you do copy that.
comment 5y ago · link · parent
async def main():
db = DB()
await db.connect('db_name', {
'host': 'localhost',
'port': '5432',
'database': 'db_name',
'username': 'db_user_name',
'password': 'db_user_password'
}, default=True)
await db.connect('other_db_name', {
'host': 'localhost',
'port': '5432',
'database': 'other_db_name',
'username': 'db_user_name',
'password': 'db_user_password'
}, default=False)
db.connection('other_db_name')
db.default = 'other_db_name'
await db.stop()
asyncio.run(main())
Am I missing something ? It's using asyncio.run() in other examples, so it assumes 3.7+ anyway.comment 5y ago · link · parent
But then I tried to think of a code where I would rather use this than a list comprehension or yield and a more manual control flow.
And I couldn't.
Those streams are elegant when the business logic flows perfectly like a river. Unfortunately, reality is messy, and production code will have matching, conditions, casting, extractions and transformations all over the place, leading to:
- very long chains of calls
- hard to change code when feedback pushes for it
- limiting your tooling (specially debuggers) to stuff that have exceptional support of chaining, and it's rare
comment 5y ago · link · parent
I get that scoping trough nurseries is the trio selling point, but you do need to have the ability to run something "before" and "after" a lone async call, and I don't want to have to write a "with" block to wrap any single thing that I wish to await.
By having "await" as a universal construct, we allow trio (or anything really) to offer an additional level of granularity - scoping a group of async calls - without losing the smaller one: scoping a single call.
comment 5y ago · link · parent
That's fair.
I'm also biased by the fact I really like to know when my code is suddenly going into async territory.
I like the JS model for this: it's explicit enough that there is little surprise (promises are now a standard, so if something returns a promise, it's async), but implicit enough that I don't have to care (no loop to setup, no coroutine instantiation between calling and scheduling). And it aged well: future can now just be awaited, and you can simply keep the callback api in non async function.
gevent is too implicit to my taste I guess. Now you could argue that we could make gevent calls explicit, but then it would be not that much different from asyncio.
I would really be happy if the community would settle in something like:
@autorun
async def coro(): ...
Then: coro() # this calls create_task(), and binds it to the upper nursery
I think it would strike the right balance from a usability point of vue.As for the interoperability issue, it's a pretty though nuts to crack.
comment 5y ago · link · parent
But there are still stuff I use bash for because it's way more efficient for one liners and small utilities.
One of the things is that calling something in bash autoprints, unless you pipe it. Could it be done in Python?
Well, it turns out you can, if you do a little dirty hacking with __call__, __repr__, __iter__, __or__ and __del__, you get:
https://0bin.net/paste/XeMvMuSh#45izWhAtQ5Bd14PDWoBqTJMvHZXa...
Which will let you do:
-ls('/etc'), auto prints all the files in the dir, in the shell and in a program.
- ls('/etc') | keep(r'\.conf$'), pipe the output of ls, pass it to keep, filter it, then auto print it (again, works in the shell AND in a py file)
- res = ls('/etc') | keep(r'\.conf$'), store the generator in the variable, doesn't print, doesn't calculate, ready to be able to be read with a for loop
This means we could create a lib with a very shell like experience in python for all those 5-lines-scripts that are still too good to pass bash for.
We could also make a @main decorator to auto run a function if __name__ == "__main__", borrow the "with cd()" and "with temp()" syntax from the fabric lib.
The need for bash would get smaller and smaller for me. I rarely develop on a linux box that doesn't have python, after all.
Now a problem people often hit is: yes, but you have to provide the dependency to your script. ShellJS proves that despite that, it has a great value already.
But the good news is, it's not a problem anymore thanks to a great features of Python 3: zipapps. With shiv (https://shiv.readthedocs.io/en/latest/), you can bundle your python script and all its dependencies (including our dirty shell lib) in a single pyz file, which then can run anywhere there is a modern python, which is everywhere I personally need it.
comment 5y ago · link · parent
SQLalchemy last version is asyncio compatible now: https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.htm...
> network libraries and entire web frameworks for the sake of two new keywords
The trend in the community now is SansIO: https://sans-io.readthedocs.io
You create entire libs without the IO parts, dealing only with the business logic.
The you let the I/O libs to deal with the rest. This allows modern project to provides a sync and async API with the same protocol implementation. E.G: https://github.com/encode/httpx
Also, I'm pretty glad gevent has not been adopted:
- it's very hard to know if you are doing something wrong with gevent. Or doing something with gevent at all.
- gevent magic patching broke stuff in unpredictable ways, and the solution was to disable part of it: https://stackoverflow.com/questions/8678307/gevent-monkeypat...
- gevent didn't play well with stdlib threads and multiprocessing, (had its own thread pool, subprocess wrapper, and no multiprocess story) while asyncio has a very good interoperability story
- the asyncio pluggable loop meant we didn't need a perfect solution out of the box. Thanks to that design, we have been able to integrate the nodejs loop, like with the uvloop project, giving birth to stuff like asgi, fastapi and uvicorn. Asyncio can now comparable async perfs as Go. (gevent does that, but forces you to, and having libuv in the stdlib is not something the core devs would want).
- gevent is a 5mo package. It's 1/6 of the ENTIRE python installer.
- the coroutine based design means we have a standard api for async, no matter the backend or implementation. Which means solution like trio were able to emerge, and eventually the core dev are now considering including trio-like scoping in the next asyncio iteration.
There are plenty of problems with asyncio though:
- create_task is basically a goto. See trio for a solution.
- coro() does not run the coro task. In JS it does, and returns a future you can await, or not. This makes it very confusing to beginner that get lost in the await/return/create_task dance.
- there is no concurrency limiting primitive, cancellation is hard and back pressure mitigation is non existent.
I was very skeptical about asyncio, but after 3.7, it became quite nice. asyncio.run() made all the difference, ergonomically, and when dealing with errors.
comment 5y ago · link · parent
- it's portable accross OSes (and keep flags if the OS supports it, deal with encoding, etc)
- it ensures selinux context is saved if there is such a thing
- it has proper and rich error communication with the calling code
- it's includes documentation and comments
- it outputs json par parsing and storage
No to say "mv" is not awesome, because it is. There is much more boiler plate in python, and is why I'll often do subprocess.check_call(['mv', 'src', 'dst']) if my script is linux only.
But you are pushing it
comment 5y ago · link · parent
Now I want to emphasis that guilt is not a good reason to start with beyond meat.
The desire to try to do a nice thing can be, but as a vegetarian, it's important that people are not pushed out of meat because of some negative emotion.
I'd rather have happy meat eaters than frutsrated veggies.
But give it a try, just for curiosity sake.
I like the taste of BM, but find them hard to digest.
Also remember it's still process food, and organic free range steak is likely healthier.