FU Logo
  • Startseite
  • Kontakt
  • Impressum
  • Home
  • Listenauswahl
  • Anleitungen

[linux-minidisc] [PATCH 5/6] Export methods to release resources.

<-- thread -->
<-- date -->
  • From: Vincent Pelletier <plr.vincent@gmail.com>
  • To: linux-minidisc@lists.fu-berlin.de
  • Date: Tue, 26 Jan 2010 21:25:59 +0100
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:in-reply-to:references:from:date:subject:to:x-length :x-uid:mime-version:content-type:content-transfer-encoding; b=dbeC6VfLwH/nj8bN7EvMho/WJDNxyvJMgWnGEUeWe5+XZ+BU/M3t/No1vHUv+VBRtL RjvcJRvTRzMoLB360L9WpKkYSej1+5esnDLwlpBSRJRQ+d7MXZXrD3rUwoBt1CKn9Uh/ RWvt6kZXHzMYlNRCvrpp9C1YnYC4/KpAq8AsM=
  • Subject: [linux-minidisc] [PATCH 5/6] Export methods to release resources.

This allows user to work-around race conditions in interpreter shutdown,
where context might be freed before handle - for example.
---
 netmd/usb1.py |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/netmd/usb1.py b/netmd/usb1.py
index e9e3ea1..d22f52a 100644
--- a/netmd/usb1.py
+++ b/netmd/usb1.py
@@ -9,11 +9,19 @@ __all__ = ['LibUSBContext']
 STRING_LENGTH = 256
 
 class USBDeviceHandle(object):
+    handle = None
+
     def __init__(self, handle):
         self.handle = handle
 
     def __del__(self):
-        libusb1.libusb_close(self.handle)
+        self.close()
+
+    def close(self):
+        handle = self.handle
+        if handle is not None:
+            libusb1.libusb_close(handle)
+            self.handle = None
 
     def getConfiguration(self):
         configuration = c_int()
@@ -313,8 +321,13 @@ class LibUSBContext(object):
         self.context_p = context_p
 
     def __del__(self):
-        if self.context_p is not None:
-            libusb1.libusb_exit(self.context_p)
+        self.exit()
+
+    def exit(self):
+        context_p = self.context_p
+        if context_p is not None:
+            libusb1.libusb_exit(context_p)
+            self.context_p = None
 
     def getDeviceList(self):
         device_p_p = libusb1.libusb_device_p_p()
-- 
1.6.6





<-- thread -->
<-- date -->
  • linux-minidisc - January 2010 - Archives indexes sorted by:
    [ thread ] [ subject ] [ author ] [ date ]
  • Complete archive of the linux-minidisc mailing list
  • More info on this list...

Hilfe

  • FAQ
  • Dienstbeschreibung
  • ZEDAT Beratung
  • postmaster@lists.fu-berlin.de

Service-Navigation

  • Startseite
  • Listenauswahl

Einrichtung Mailingliste

  • ZEDAT-Portal
  • Mailinglisten Portal