New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bin files not closed after reading #29
Comments
i suppose Line 435 in ad72f97
should close it when you invoke shutdown()
|
Yes, I think too that actually it is closing, but I am afraid the warning comes from the local variable I was wondering if it is possible to do something like this: if test_file:
with open(test_file, 'rb') as f:
self._shared_mem = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
#.... |
maybe file will be closed as soon as you exit |
OK, I will definitely try and bring up the results |
so, using a file context: if test_file:
with open(test_file, 'rb') as f:
self._shared_mem = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
self.__is_using_test_file = True and with this simple test: import re
from pathlib import Path
from unittest import TestCase
import irsdk
class IrsdkTest(TestCase):
client = irsdk.IRSDK()
def setUp(self) -> None:
# import warnings
# warnings.filterwarnings(action="ignore", message="unclosed", category=ResourceWarning)
...
def tearDown(self) -> None:
self.client.shutdown()
class BasicsTest(IrsdkTest):
def test_data_is_good(self):
"""Test if data is well logged"""
car_idx = 16
files = list(Path("tests/resources/mc_p217_mosport").glob("*.bin"))
self.assertTrue(files)
for file in files:
with self.subTest(file=file.name):
self.client.startup(test_file=str(file))
self.assertEqual(
self.client['DriverInfo']['DriverCarIdx'], car_idx,
"Current player should be CarIdx = 16"
)
file_lap = re.match(r'^lap(\d{0,3})\.bin', file.name).group(1)
self.assertEqual(
self.client['CarIdxLap'][car_idx], int(file_lap),
"Lap from data dump should match with file_name"
)
self.tearDown() Test works and no
Note that I am directly checking info from the bin file, If I reset the code in irsdk:
|
when done maybe we should store file descriptor and close it in try store |
Sorry Kutu, I forgot to copy and paste here the Also sorry about your last comment but I didn't understand; when done is when you put that resource into shared memory, and you store it into Just to clarify, in my test, in every attempt to read a new bin file, i am using |
I've made more tests using different python versions to ensure consistency. The above change does not print 3.11.1 ✅ |
the quote was from try with this version https://www.dropbox.com/s/rqmu1dygy1ainna/irsdk.py?dl=1 |
Ok, I think you mean this url: In that paragraph:
I still understand that "when done" refers to "when you create the shared memory resource", but it seems pretty ambiguous to me... I would go to use local variable and avoid to save that into a class attribute, but if you want to save into private attribute the I've tested your code and still works for the 3 python versions. |
with that logic you can do f = open(...)
fn = f.fileno()
f.close()
mmap.mmap(fn...) don't think its fine |
No, I never meant to say that, but rather after you call f = open(...)
fn = f.fileno()
mmap.mmap(fn...)
f.close()
del f # what python does once startup() method finished The snippet you passed never should work. Indeed:
|
Hi Kutu,
First of all thank you for this library!
I've been using
*.bin
files and I receive all the time thattracemalloc
RuntimeWarning
every time Iir.startup(test_file=my_bin_file)
.Looking at the source code I see that the file is opened but not closed after reading. Is this on purpose?
pyirsdk/irsdk.py
Lines 415 to 418 in ad72f97
Right now I am supressing that warning to not overwhelm my console log, but I was wondering if this could be fixed somehow.
I am happy to help by sending a PR fixing this if you want but maybe there's something that i am missing out.
Thanks again in advance!
The text was updated successfully, but these errors were encountered: