« first day (4541 days earlier)      last day (599 days later) » 

00:20
I don't know why, but I got rate limited for a little.
@RydwolfPrograms that's actually what i ended up doing if you check out the python code
 
5 hours later…
05:13
@user true. But there is no way for you to close the file as there is no reference to the file handle
@Simd it is your responsibility to keep your file handle, like file_handle = open("file.pkl", "rb"); obj = pickle.load(file_handle); close(file_handle)
or with statement handles automatic closing for you
or if you're on 3.8 or later, pickle.load(file_handle := open(...)) is also an option
@Bubbler yes. I am just interested what cPython does when there is no reference to the file handle
This claims it might be closed immediately stackoverflow.com/questions/24876837/closing-files-in-cpython
 
11 hours later…
16:36
@DLosc Can confirm: it is tomorrow, I am living, and I still need to loosen up
@Simd does cpython immediately free when refcount reaches 0?
@DLosc no, it's today silly
And ofc I'm not living, I'm DLosc
Python never actually frees, it will keep the memory if another object of the same size needs allocation
17:11
I guess GCs don't usually call the C free, but when the refcount reaches 0, does the GC immediately clean up and does CPython's own allocator immediately treat those objects as being free?
17:32
You could check by adding a print to the __del__ dunder
I'm not sure myself
18:16
@user I don't know and I can't find anyone who does know
@mousetail that's an interesting idea
18:28
@Simd You shouldn't count on the file being closed by GC. It's unreliable, but it may happen
Unless, of course, you're code golfing, in which case you should definitely count on the file being closed by GC (or by the OS, or by rebooting your computer eventually). ;)
If your program will exit anyway in a few moments it doesn't really matter
19:11
@DLosc Why would I close the file? That wastes bytes
Precisely
19:35
@mousetail ok thanks. But there is no way to close it either
@DLosc 😁
It just seems odd to have a situation where you can't close a file but you should assume it might need closing
Why? If python decides the file is unused it will be closed. It's just that making sure you detect when something is unreferences with 100% accuracy is unfeasable
Is is still possible to close it using file descriptors? I'm not familiar with low-level file handling in Python.
afaik yes
os.fdopen exists, at least
@DLosc I once saw a story somewhere about missiles whose software had memory leaks. It was okay for them because the missile would go kaboom anyway. I'm thinking we can treat normal computers the same way - they'll turn into trash at some point anyway
Planned obsolescence taken to the next level
20:06
@DLosc that sounds interesting. I would love to see how
@mousetail I wrote a loop that opens the same time in each iteration with no problem. It must be closing the file quickly
You can have a few million files open at once
You can check if the fileno's are increasing
20:21
@mousetail how do you do that?
There is only one file
.getfileno
Fun fact: Many python buitins just use getfileno and ignore the .read and .write methods so won't work on custom files that don't have one
20:35
0
A: Sandbox for Proposed Challenges

CursorCoercerCritical Calculations code-golfgamestatistics Background In the game stick ranger, there is an item which grants the character the ability to get critical hits. Each time a projectile hits an enemy, it has some probability to be a critical hit (crit). For most weapons this is calculated and reset...

21:27
posted on July 06, 2023 by trichoplax‭

You roll $N$ dice simultaneously. Your score is the highest number rolled. If you play this game many times, what is the expected value (mean) of your score? Input A pos...


« first day (4541 days earlier)      last day (599 days later) »