PageRenderTime 24ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/pp-1.6.0/ppcommon.py

#
Python | 63 lines | 22 code | 8 blank | 33 comment | 5 complexity | 94716989fc4187faaf2af1c17860f00a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # Parallel Python Software: http://www.parallelpython.com
  2. # Copyright (c) 2005-2010, Vitalii Vanovschi
  3. # All rights reserved.
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are met:
  6. # * Redistributions of source code must retain the above copyright notice,
  7. # this list of conditions and the following disclaimer.
  8. # * Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. # * Neither the name of the author nor the names of its contributors
  12. # may be used to endorse or promote products derived from this software
  13. # without specific prior written permission.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  25. # THE POSSIBILITY OF SUCH DAMAGE.
  26. """
  27. Parallel Python Software, Execution Server
  28. http://www.parallelpython.com - updates, documentation, examples and support
  29. forums
  30. """
  31. import threading
  32. copyright = "Copyright (c) 2005-2010 Vitalii Vanovschi. All rights reserved"
  33. version = "1.6.0"
  34. def start_thread(name, target, args=(), kwargs={}, daemon=True):
  35. """Starts a thread"""
  36. thread = threading.Thread(name=name, target=target, args=args, kwargs=kwargs)
  37. thread.daemon = True
  38. thread.start()
  39. return thread
  40. def get_class_hierarchy(clazz):
  41. classes = []
  42. if clazz is type(object()):
  43. return classes
  44. for base_class in clazz.__bases__:
  45. classes.extend(get_class_hierarchy(base_class))
  46. classes.append(clazz)
  47. return classes
  48. def is_not_imported(arg, modules):
  49. args_module = str(arg.__module__)
  50. for module in modules:
  51. if args_module == module or args_module.startswith(module + "."):
  52. return False
  53. return True
  54. # Parallel Python Software: http://www.parallelpython.com