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
All of this works fine with python 2.7 as long as you put the rest of your code in your main() entry point, which you should do anyway. So an f-string would cause no problem.
Also, "informative stack trace" is only informative to another dev, and an experienced one at that, given how many juniors I encounter that can't read a traceback.
Indeed, you script users may not be devs, and for those, a traceback would be confusing. For this reason, a script should only output a traceback in dev mode, but in production, if the dev flag is not set (-X dev), you should never see a traceback. It's a good practice to suppress it with sys.excepthook, and log it into a file instead.
Using a syntax error like you do for this purpose IS the big hack.
Now I'm not against a hack. I can see the value of it for your own scripts, of things that you code quick and dirty style. After all, I don't always want to have a clean entry point and more than one file.
comment 5y ago · link · parent
import sys
if sys.version_info < (3, 6):
print('This script requires python 3.6+)
else:
from module import main
main()
If you want all of it to be in one file, you can use a zipapp: https://docs.python.org/fr/3/library/zipapp.htmlIf you don't want to make the zipapp manually, or want it to automatically extract everything on first run, use shiv:
comment 5y ago · link · parent
Besides, it doesn't work on Windows, if you want a zipapp, shiv is a better alternative: http://shiv.readthedocs.io
comment 5y ago · link · parent
comment 5y ago · link · parent
I always use both at the same time.
Hierarchy gives you a way to organize things according to each others. I want hierarchy, because if I deal with thing A, I may have then to specifically have a look to child B or C.
It helps with context and granularity.
While tags allow you to attach multiple categories to things and filter according to that.
You can use a hierarchy as a poor man tag, but really, you should use both.
comment 5y ago · link · parent
Like MS in the 90'.
Don't worry, in 20 years, all their PR will say they are your best friend again. They will be the underdog for some unforseen reason, and will suddenly call for respecting your private life, encrypting everything and give power to the user.
The way MS does it for open source today.
It's the circle of life for corporations.
comment 5y ago · link · parent
Flask-SQLalchemy is not well integrated at all. E.G: try to play with it in the shell, the session management is annoying as hell.
As of flak-login, it doesn't have a tenth of the
Also you forgot: csrf handling, i18n, xss, click hijacking, cache backends, and so on. That's again, more plugins you have to select.
And that's a lot to configure, learn doc, then upgrade when the times come, on top of that.
All of them will, obviously, not be compatible with SQLA 2 next year, because the projects are not a whole, so it's going to be even more fun on the months to come.
I really think a beginner should not use that.
comment 5y ago · link · parent
While I don't buy that this is the only view at the time, and that there was no dirt to find, I believe that there was a time were ads were imagined as a way to inform the consumers, or at least convey some kind of information to them.
Unfortunately, the market doesn't optimize for what's right, only for what's profitable. The too may or may not aligned at first, but give it enough time, and it will deviate.
comment 5y ago · link · parent
It depends. My advice is always: stick to django no matter what, unless you are a seasoned web devs. I've seen too many flask projects with terrible architecture decisions and security holes because flask assumes (by nature) you can take those decisions.
Those decisions are not easy to take. They require a deep knowledge of the field.
So yes, one may chose flask or fast api as a lighter alternative, provided they know very well what they are doing, or that the consequences of not knowing are small. The later is not always simple to evaluate however, especially if you are not experienced. You don't know what you don't know after all.
If somebody doesn't know if they are an experienced web dev, or the consequences of their choices, they should use Django.
It will save them from SQL injection, XSS, Cross request forgery and click hijacking. It will provide an pluggable auth backend should you need it later. It will force you to put some parts of your code in separate sillows. This is a good thing for most people.
comment 5y ago · link · parent
Removing imperfections will become the norm, the way photoshoping magazing covers is, with all the social consequences.
In fact, people will confuse what the machine think we look like, with what we actually look like, and I'm bracing for the bias that it will create.
comment 5y ago · link · parent
https://developer.nvidia.com/ai-video-compression
Basically it creates an AI model of your face, send that to the other party, and then when you move, it only sends key face points. The other party uses the AI model to create a virtual hi-res picture of you, thispersondoesnotexist style, except it looks perfectly like you. Then it uses the face points to move it the way you move.
The result: it consumes almost no bandwidth and you get the experience of a hi-res video call.
Of course, then I realized the trap: it's a perfect honey pot to get everyone to scan their face.
This is, IMO, what's going to happen with the VR. Big companies like Facebook/Meta are going to use the online avatar as a motivator to let them scan everything that can identify you. It will make the virtual you so realistic! Scan your face, your cat, your whole flat!
People will jump on that, with no thinking about the consequences what so ever. After all, they are crazy about the way services like snapchat can change your face on a video.
It's already game over. Like with Ken of the North star, we don't know it, but we are already owned.
comment 5y ago · link · parent
Django's API is now clearly dated. I still use it massively though, because it's insanely productive for CRUD apps, which are 99% of my client requests.
They made some hard choices about the auth and db layer, and they are imperfect, but when left to do the choice myself in other frameworks, I often miss Django. You really value all it gives you once you've lost it.
comment 5y ago · link · parent
I would say it's pretty hard to add an await in the wrong place, although not impossible. I think it's easier to:
- forget an await
- forget a asyncio.wait or a asyncio.gather
The later is very common, and is being addressed by the structured concurrency movement we've seen with Trio and the likes. This should end up in mainline python eventually because it is, indeed, a problem.
However, it's still way easier to shot yourself in the foot with concurrency and threads than with asyncio.
However, it is harder to startup with asyncio than with threads, because there is more to learn just to boot.
comment 5y ago · link · parent
Not to mention you should cook, buy fresh food, stay informed, be politically active, learn new things, keep your house clean, recycle, do health checks up, get a hair cut, but don't use your car for everything and spend some time in nature. Don't forget to read, meet new people, get to zero inbox and fix your shower curtain.
comment 5y ago · link · parent
- async python is faster, but for a very specific niche of workload. Most tasks you do don't fit that workload at all. Which mean most of the time, you should NOT use async Python. And it's ok. Don't make your code complicated when you don't need it. Chose a tech for the need, not the hype.
- async python is not just for performances. It helps with making some specific kind of concurrency easy to reason about, because the context switch is explicit, and the chain of event can appear linearly in the code, thanks to await.
- it's ok to have some sync processes and some async processes. It's not one or the other.
- async is not a replacement for threads or processes. In fact, there are good use cases for having several processes, each with several threads, each with one event loop. Which also means that if you benchmark your WSGI code with 16 workers, you should do so as well with your aWSGI one.
The corollary to this is that some web site loads are very well suited for async (e.g: an SPA with a lot of connectivity which delegates long running code to other services), but a lot are not. If each request makes a long SQL query, seeks the hard drive, dynamically performs i18n and adds some calculation on top, it may very well block the event loop for too long, killing any benefit.
So when would you use async python ?
- For performances, when you need to maintain numerous long connections. E.G: doing websockets ? Use asyncio. Serving static files without nginx ? Use asyncio. Want to create a web crawler and your memory budget does not allow to open 10000 threads ? Use asyncio.
- For the interface, use the async/await keywords everywhere you need need inversion of control for I/O. It's not just about perf here, it's also a mechanism to delegate arbitrary parts of your code with a common standard interface around a fancy state machine + scheduler. You can use that to abstract all your I/O and switch backends at will, while offering callback inlining.
But again, you have awesome threading and multiprocessing pools with python. Not to mention tools like zeromq, scrapy or celery, which do a lot for you. Don't run to async just because "it's faster".
Having async by default in frameworks like fastpi opens up a ton of possibility though. Live settings, pub/sub between processes, websockets...
comment 5y ago · link · parent
I would add I started experiencing time slowing down once I did a one year stay at a Vipassana center. I also meditate 2 hours a day now. My first 10 years of meditation, I didn't felt it.
So maybe, it's dose dependent.
Or maybe it's all in my head :)
comment 5y ago · link · parent
I can only tell you what I have done, the cost and benefit I personally experienced. I cannot make recommendations as it would be utter B.S.
I'm pretty good with my brain, but my attention was lacking to say the least. In search for a solution, I tried meditation on my own. I read books, and tried to sit down by myself.
I failed. Repeatedly.
Frustrated by what was the first time not being good with my head, I ask my doctor, who I knew was a Buddhist doing meditations retreats in caves, to help me find a teacher.
I insisted I wanted meditation only. No mantra or singing. No mythology or holly texts. No prayer or God. No offering, ritual or altar.
She told me the closest thing to what I was looking for was a course of "Vipassana Meditation, in the tradition of S.N Goenka".
It's a meditation technique that you learn during a 10 days courses. Shorter periods are NOT available as a beginner, and the 10 days are really necessary. I advice strongly against quitting in the middle of a course, for your own mental health, even if you believe you can. Once your are in it, you should finish.
You _will_ want to quit. Almost everybody does. Sometimes, I still do on the first day, when I start a new course.
The 10 days are not devoid of mysticism, religious undertone, etc. but they do teach you a technique that can be practiced as an atheist, or a practitioner of another religion, with minimal fuss. Keep in mind, though, that if you are scientifically inclined, the 10 days will grind your gears in many ways. After so long, it still triggers me sometimes, but I've being involved with those people quite deeply now, and I find solace in the fact they are benevolent and dedicated to helping.
I actually lived a year in one of the (numerous, almost 200 in the world) meditation centers, I dated one their accountant (!), and being part of a lot of their activities. They are just regular human beings, with the good, and the bad, but they really want to help, and they do. The accounting books are clean too ^^
The course is free, and you don't need to pay for the teaching, nor the accommodation, or the food. Ever. They will regularly remind you they need donation, and even tell you it's good for you :) I do donate, but it is completely optional, and some people never give anything. It's considered perfectly ok.
As for the 10 days course, it is _hard_. The discipline is strict:
- waking up at 4 am
- no food after 12
- you put any distracting object in a safe you can't access before the end, including your phone, books, wallets or notebooks
- you can't talk, do much exercise
- you meditate 10 hours a day
The hardest part is not the silence, the food or the sleep though. It's the meditation. Provided you practice correctly, it will be extremely challenging. Boredom, physical discomfort or pain, distress, depression, break down, sadness, etc. are only a fraction of the things you may, or may not have to face. And that's only what you can put words on, which is, to my surprise, only a very tiny part of the experience.
The cost, hence, is high.
It's even higher if you decide it's worth it for you to carry on with it daily. It takes time, and effort.
Also, it's a slow process. A steady one, mind you. My life has changed in ways I believe would have not been possible otherwise. Some progresses fade without practice. Some gains are for life even if you stop.
But I've been at it for some time now, and I will continue for the rest of my life. The trade off proved worth it for me.
The most obvious benefits that I personally experienced:
- my social, love and professional life have completely shifted. I had what looked like autistic traits, but they have melted. I'm considered an extrovert now.
- I am happier. It was not a straight transformation. I had depressive periods. But the trend on 15 years is that, all in all, I'm much, much happier than when I started. This by itself makes the technique worth it, as it leads you, little by little, to decouple happiness from circumstances.
- I know myself better. This means I accept myself more as I am, I have less illusion about myself, and also I live my life according to that knowledge, instead of hitting an invisible wall. If I'd share what I learned with you, you would think it's trivial, obvious things. But making them yours make all the difference.
- I'm more productive. It's a small detail compared to the rest, but a nice boost.
- I am more at peace with the suffering of our human condition. Less afraid of death, less angry with people destroying things, less depressed by the state of society. I forgive a lot now. Including myself. I'm ok hurting people too, which is strange to say, and not what you think would be the result of meditation.
In fact, I became less minimalist and more materialist with time. I don't look the stereotype of a wise, zen person. Also, some areas in my life I desperately wanted to work on didn't move at all. I eat too much, I still get angry for some things that are so superficial in retrospect. So be careful with expectations.
You can find more information about this particular technique and the related courses here:
https://www.dhamma.org/en-US/index
Yes, I'm well aware that the website looks like a cult.
It's even worse when you are in a course, with the Pali wows and the recordings repeating again and again the same instructions.
You will have to assess that by yourself.
Whatever you chose to do, I hope you'll find something that works for you.
comment 5y ago · link · parent
I have been practicing meditation for 15 years, sometimes in batch of 100 hours.
The more I practice, the more the time slows down. Not just while meditating, but after the fact as well. Although it fluctuates and I'm not back to my kid self, it feels that I have tremendously more time now than a few years ago.
I suspect that it's tied to how much present you manage to be.
When you are a kid, you are deeply immersed in whatever you are doing, and less and less so after that, especially in our age of distractions, multitasking, and intellectual work loads.
I think that the more you are immersed in the daily boring stuff, like just walking, doing chores, or taking your shower, the more you register the time you spend doing said activity, and the time seems to pass slowly.
In fact, I am sometimes under the impression my minutes, not just feel longer, but actually contain more, because I do so many things and then looking at the clock, it hasn't moved much. This sensation increases when I meditate a lot.
comment 5y ago · link · parent
comment 5y ago · link · parent
But if you are interested on removing the GIL, you gonna love 2022: https://docs.google.com/document/u/0/d/18CXhDb1ygxg-YXNBJNzf...