udev: fix writting to the device
Signed-off-by: Filipe Laíns <lains@archlinux.org>
This commit is contained in:
parent
7a4f7bbb84
commit
6b14004a6f
|
@ -30,6 +30,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
||||||
|
|
||||||
import os as _os
|
import os as _os
|
||||||
import errno as _errno
|
import errno as _errno
|
||||||
|
from time import sleep
|
||||||
from select import select as _select
|
from select import select as _select
|
||||||
from pyudev import Context as _Context, Monitor as _Monitor, Device as _Device
|
from pyudev import Context as _Context, Monitor as _Monitor, Device as _Device
|
||||||
from pyudev import DeviceNotFoundError
|
from pyudev import DeviceNotFoundError
|
||||||
|
@ -261,16 +262,16 @@ def write(device_handle, data):
|
||||||
assert data
|
assert data
|
||||||
assert isinstance(data, bytes), (repr(data), type(data))
|
assert isinstance(data, bytes), (repr(data), type(data))
|
||||||
retrycount = 0
|
retrycount = 0
|
||||||
while(True and retrycount < 3):
|
bytes_written = 0
|
||||||
try:
|
while(retrycount < 3):
|
||||||
bytes_written = _os.write(device_handle, data)
|
bytes_written = _os.write(device_handle, data)
|
||||||
if bytes_written != len(data):
|
if bytes_written != len(data):
|
||||||
raise IOError(_errno.EIO, 'written %d bytes out of expected %d' % (bytes_written, len(data)))
|
sleep(0.1)
|
||||||
except IOError as e:
|
|
||||||
if e.errno != _errno.EPIPE:
|
|
||||||
raise e
|
|
||||||
retrycount += 1
|
retrycount += 1
|
||||||
continue
|
else:
|
||||||
|
break
|
||||||
|
if bytes_written != len(data):
|
||||||
|
raise IOError(_errno.EIO, 'written %d bytes out of expected %d' % (bytes_written, len(data)))
|
||||||
|
|
||||||
|
|
||||||
def read(device_handle, bytes_count, timeout_ms=-1):
|
def read(device_handle, bytes_count, timeout_ms=-1):
|
||||||
|
|
Loading…
Reference in New Issue