Skip to content

Commit e860705

Browse files
committed
close uinput in __exit__ only if a fd exists
1 parent a03f389 commit e860705

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

evdev/uinput.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def __enter__(self):
9191
return self
9292

9393
def __exit__(self, type, value, tb):
94-
self.close()
94+
if hasattr(self, 'fd'):
95+
self.close()
9596

9697
def __repr__(self):
9798
# :todo:
@@ -111,12 +112,12 @@ def __str__(self):
111112
return msg
112113

113114
def close(self):
114-
# close the associated InputDevice, if we managed to open it
115+
# close the associated InputDevice, if it was previously opened
115116
if self.device is not None:
116117
self.device.close()
117118

118119
# destroy the uinput device
119-
if self.fd and self.fd > -1:
120+
if self.fd > -1:
120121
_uinput.close(self.fd)
121122
self.fd = -1
122123

0 commit comments

Comments
 (0)