home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fnb101.zip / Lib / site-packages / Fnorb / orb / ThreadSpecificData.py < prev    next >
Text File  |  1999-06-28  |  2KB  |  74 lines

  1. #!/usr/bin/env python
  2. #############################################################################
  3. # Copyright (C) DSTC Pty Ltd (ACN 052 372 577) 1997, 1998, 1999
  4. # All Rights Reserved.
  5. #
  6. # The software contained on this media is the property of the
  7. # DSTC Pty Ltd.  Use of this software is strictly in accordance
  8. # with the license agreement in the accompanying LICENSE.DOC file.
  9. # If your distribution of this software does not contain a
  10. # LICENSE.DOC file then you have no rights to use this software
  11. # in any manner and should contact DSTC at the address below
  12. # to determine an appropriate licensing arrangement.
  13. #      DSTC Pty Ltd
  14. #      Level 7, Gehrmann Labs
  15. #      University of Queensland
  16. #      St Lucia, 4072
  17. #      Australia
  18. #      Tel: +61 7 3365 4310
  19. #      Fax: +61 7 3365 4311
  20. #      Email: enquiries@dstc.edu.au
  21. # This software is being provided "AS IS" without warranty of
  22. # any kind.  In no event shall DSTC Pty Ltd be liable for
  23. # damage of any kind arising out of or in connection with
  24. # the use or performance of this software.
  25. #
  26. # Project:      Distributed Environment
  27. # File:         $Source: /units/arch/src/Fnorb/orb/RCS/ThreadSpecificData.py,v $
  28. #
  29. #############################################################################
  30. """ A class for thread-specific data. """
  31.  
  32.  
  33. # Fnorb modules.
  34. import fnorb_thread
  35.  
  36.  
  37. class ThreadSpecificData:
  38.     """ A thread-safe dictionary class. """
  39.  
  40.     def __init__(self):
  41.  
  42.     self.__lk = fnorb_thread.allocate_lock()
  43.     self.__data = {}
  44.  
  45.     return
  46.  
  47.     def get(self):
  48.     """ Get the value for the current thread. """
  49.  
  50.     self.__lk.acquire()
  51.     try:
  52.         value = self.__data[fnorb_thread.get_ident()]
  53.  
  54.     finally:
  55.         self.__lk.release()
  56.  
  57.     return value
  58.  
  59.     def set(self, value):
  60.     """ Set the value for the current thread. """
  61.  
  62.     self.__lk.acquire()
  63.     try:
  64.         self.__data[fnorb_thread.get_ident()] = value
  65.  
  66.     finally:
  67.         self.__lk.release()
  68.  
  69.     return
  70.  
  71. #############################################################################
  72.