Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #
  2. # Support for the API of the multiprocessing package using threads
  3. #
  4. # multiprocessing/dummy/__init__.py
  5. #
  6. # Copyright (c) 2006-2008, R Oudkerk
  7. # All rights reserved.
  8. #
  9. # Redistribution and use in source and binary forms, with or without
  10. # modification, are permitted provided that the following conditions
  11. # are met:
  12. #
  13. # 1. Redistributions of source code must retain the above copyright
  14. # notice, this list of conditions and the following disclaimer.
  15. # 2. Redistributions in binary form must reproduce the above copyright
  16. # notice, this list of conditions and the following disclaimer in the
  17. # documentation and/or other materials provided with the distribution.
  18. # 3. Neither the name of author nor the names of any contributors may be
  19. # used to endorse or promote products derived from this software
  20. # without specific prior written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
  23. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  26. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. # SUCH DAMAGE.
  33. #
  34. from __future__ import absolute_import
  35. #
  36. # Imports
  37. #
  38. import threading
  39. import sys
  40. import weakref
  41. import array
  42. from threading import Lock, RLock, Semaphore, BoundedSemaphore
  43. from threading import Event
  44. from billiard.five import Queue
  45. from billiard.connection import Pipe
  46. __all__ = [
  47. 'Process', 'current_process', 'active_children', 'freeze_support',
  48. 'Lock', 'RLock', 'Semaphore', 'BoundedSemaphore', 'Condition',
  49. 'Event', 'Queue', 'Manager', 'Pipe', 'Pool', 'JoinableQueue'
  50. ]
  51. class DummyProcess(threading.Thread):
  52. def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
  53. threading.Thread.__init__(self, group, target, name, args, kwargs)
  54. self._pid = None
  55. self._children = weakref.WeakKeyDictionary()
  56. self._start_called = False
  57. self._parent = current_process()
  58. def start(self):
  59. assert self._parent is current_process()
  60. self._start_called = True
  61. self._parent._children[self] = None
  62. threading.Thread.start(self)
  63. @property
  64. def exitcode(self):
  65. if self._start_called and not self.is_alive():
  66. return 0
  67. else:
  68. return None
  69. try:
  70. _Condition = threading._Condition
  71. except AttributeError: # Py3
  72. _Condition = threading.Condition # noqa
  73. class Condition(_Condition):
  74. if sys.version_info[0] == 3:
  75. notify_all = _Condition.notifyAll
  76. else:
  77. notify_all = _Condition.notifyAll.__func__
  78. Process = DummyProcess
  79. current_process = threading.currentThread
  80. current_process()._children = weakref.WeakKeyDictionary()
  81. def active_children():
  82. children = current_process()._children
  83. for p in list(children):
  84. if not p.is_alive():
  85. children.pop(p, None)
  86. return list(children)
  87. def freeze_support():
  88. pass
  89. class Namespace(object):
  90. def __init__(self, **kwds):
  91. self.__dict__.update(kwds)
  92. def __repr__(self):
  93. items = list(self.__dict__.items())
  94. temp = []
  95. for name, value in items:
  96. if not name.startswith('_'):
  97. temp.append('%s=%r' % (name, value))
  98. temp.sort()
  99. return 'Namespace(%s)' % str.join(', ', temp)
  100. dict = dict
  101. list = list
  102. def Array(typecode, sequence, lock=True):
  103. return array.array(typecode, sequence)
  104. class Value(object):
  105. def __init__(self, typecode, value, lock=True):
  106. self._typecode = typecode
  107. self._value = value
  108. def _get(self):
  109. return self._value
  110. def _set(self, value):
  111. self._value = value
  112. value = property(_get, _set)
  113. def __repr__(self):
  114. return '<%r(%r, %r)>' % (type(self).__name__,
  115. self._typecode, self._value)
  116. def Manager():
  117. return sys.modules[__name__]
  118. def shutdown():
  119. pass
  120. def Pool(processes=None, initializer=None, initargs=()):
  121. from billiard.pool import ThreadPool
  122. return ThreadPool(processes, initializer, initargs)
  123. JoinableQueue = Queue