Skip to content

Commit 0d1622a

Browse files
authored
Merge pull request sonic-net#18 from yxieca/no_buffering
[sfp_util] open eeprom files with buffering disabled
2 parents b8470c5 + c799a5e commit 0d1622a

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

sonic_sfp/sfputilbase.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ def _sfp_eeprom_present(self, sysfs_sfp_i2c_client_eeprompath, offset):
198198
return False
199199
else:
200200
try:
201-
sysfsfile = open(sysfs_sfp_i2c_client_eeprompath, "rb")
202-
sysfsfile.seek(offset)
203-
sysfsfile.read(1)
201+
with open(sysfs_sfp_i2c_client_eeprompath, mode="rb", buffering=0) as sysfsfile:
202+
sysfsfile.seek(offset)
203+
sysfsfile.read(1)
204204
except IOError:
205205
return False
206206
except:
@@ -275,7 +275,7 @@ def _read_eeprom_devid(self, port_num, devid, offset, num_bytes = 256):
275275
return None
276276

277277
try:
278-
sysfsfile_eeprom = open(sysfs_sfp_i2c_client_eeprom_path, "rb")
278+
sysfsfile_eeprom = open(sysfs_sfp_i2c_client_eeprom_path, mode="rb", buffering=0)
279279
except IOError:
280280
print("Error: reading sysfs file %s" % sysfs_sfp_i2c_client_eeprom_path)
281281
return None
@@ -646,7 +646,7 @@ def get_transceiver_info_dict(self, port_num):
646646
return None
647647

648648
try:
649-
sysfsfile_eeprom = open(file_path, "rb")
649+
sysfsfile_eeprom = open(file_path, mode="rb", buffering=0)
650650
except IOError:
651651
print("Error: reading sysfs file %s" % file_path)
652652
return None
@@ -711,7 +711,7 @@ def get_transceiver_dom_info_dict(self, port_num):
711711
return None
712712

713713
try:
714-
sysfsfile_eeprom = open(file_path, "rb")
714+
sysfsfile_eeprom = open(file_path, mode="rb", buffering=0)
715715
except IOError:
716716
print("Error: reading sysfs file %s" % file_path)
717717
return None
@@ -807,7 +807,7 @@ def get_transceiver_dom_info_dict(self, port_num):
807807
return None
808808

809809
try:
810-
sysfsfile_eeprom = open(file_path, "rb")
810+
sysfsfile_eeprom = open(file_path, mode="rb", buffering=0)
811811
except IOError:
812812
print("Error: reading sysfs file %s" % file_path)
813813
return None

0 commit comments

Comments
 (0)