135201
You will be muted until you read the rules. Read them! @Rules_for_Python A group about the Python programming language. Offtopic things go here: @pythonofftopic Resources to learn python: @pythonres Group for Hy: @hylang Selenium: @SeleniumPython
you means to piont htis line:
Open the file pointed to in bytes mode, write data to it, and close the file:
https://docs.python.org/3/library/pathlib.html#pathlib.Path.write_bytes
Читать полностью…
I am so ai addicted, i didn't understand a single word lol 😂
Читать полностью…
No, to_thread should be used as a last resort (and when you know what you are doing)
Use whatever you like, just do not use to_thread() if you have other (better) options.
And learn the diffrences of async code vs using threads vs using proccesses.
You cannot work with those until you understand what those are.
You did not even read my answer or tried to understand it...
Btw,
Mongo has async driver
Why are you using PyMongo which is sync in async application??
It is called Motor - look it up
i'm finally making the move from pip to uv. it's been on my list for a while. Any warnings before I go forth? 😁
No, move MongoClient out of get_collection
You need exactly one client per process believe me, for your tasks is enough
def get_collection(): myclient = pymongo.MongoClient("mongodb://localhost:27017/") mycol = myclient["mydatabase"]["customers"] mydoc = mycol.find().sort("name")return mydocmycol = get_collection()
See if i keep this logic of search a user and keep this in a function and use with my PTB library ot fastapi to get data of a telegram user so at that moment i call this connection to fetch the data and it take 500ms so for this 500 ms my Python tg bot will not respond to anyone so this time i will call this on asyncio.to_thread(get_collection())
so what should i do? is to_thread is ok here?
My one function do fetch a image's url form internet and saves in the ssd and do some editing using the pillow.
See When i will do code in fastapi's web dev should i try to write in async way, but here pillow is not allow to write async code, so what will the way, will i make simple def sync_fun() and time of call this function will i call it via asyncio.to_thread(sync_fun) will it fully ok to use like this in fastapi web app?
i also thoughtlike this, then one day someone forcefully teach me uv and how to use it to install new library, change python verison and so on, then i never look back at pip 😅
Читать полностью…
Should pip now be completely deprecated in new projects?
you should read python docs instead of using that shit
Читать полностью…
actually ai say me this to use Path_obj.write_bytes, but previously the repo i used they also used the path_obj in the with open() block so i got so pain to decide to choose the most best?
Читать полностью…
so see when i use normal file writing in python i did,
if fmt == "txt":
with open(text_file_path, "wb") as f:
f.write(decrypted_data)
text_file_path.write_bytes -> is this ok? no memory leak or problem will occurs?
Читать полностью…
As of May 14, 2025, Motor is deprecated in favor of the GA release of the PyMongo Async API in the PyMongo library
from pymongo import AsyncMongoClient
Beanie - is an asynchronous Python object-document mapper (ODM) for MongoDB. Data models are based on Pydantic.
asyncio.to_thread(sync_mongo_fun...), so which i will use now ?
Читать полностью…
yaa it could be a good things, now after i will move client outside the fun, my cpu usage will low it will not recreatet the client all time right?
Читать полностью…
Please provide a full explanation including all the details that you consider relevant. Your statement is too broad and there is no clear way to answer you, you have to explain:
- what you're doing
- what you're expecting
- what you're using
- where you're running the script
- what Python version you're using
- what packages and their versions you're using
- and the most important thing: show the code YOU wrote (read rule 5️⃣ for that)
and more details, that way your chances to get help will increase.
While downloading is I/O bound and belongs to a thread or async, pillow and/or ffmpeg are CPU-bound, and these below in their own proccess, not a thread
Читать полностью…
Hello everyone. I'm new here ready to learn and build using python. How would you recommend me to start
Читать полностью…