コード例 #1
0
ファイル: parallel.py プロジェクト: sjg20/chromite
def Manager():
  """Create a background process for managing interprocess communication.

  This manager wraps multiprocessing.Manager() and ensures that any sockets
  created during initialization are created in '/tmp' rather than in a custom
  temp directory. This is needed because TMPDIR might be really long, and
  named sockets are limited to 108 characters.

  Usage:
    with Manager() as manager:
      queue = manager.Queue()
      ...

  Returns:
    The return value of multiprocessing.Manager()
  """
  old_tempdir_value, old_tempdir_env = osutils.SetGlobalTempDir('/tmp')
  try:
    m = HackTimeoutSyncManager()
    # SyncManager doesn't handle KeyboardInterrupt exceptions well; pipes get
    # broken and E_NOENT or E_PIPE errors are thrown from various places. We
    # can just ignore SIGINT in the SyncManager and things will close properly
    # when the enclosing with-statement exits.
    m.start(IgnoreSigint)
    return m
  finally:
    osutils.SetGlobalTempDir(old_tempdir_value, old_tempdir_env)
コード例 #2
0
ファイル: parallel.py プロジェクト: zhangjiayun/chromium.bb
def Manager():
    """Create a background process for managing interprocess communication.

  This manager wraps multiprocessing.Manager() and ensures that any sockets
  created during initialization are created under the /tmp tree rather than in a
  custom temp directory. This is needed because TMPDIR might be really long, and
  named sockets are limited to 108 characters.

  Examples:
    with Manager() as manager:
      queue = manager.Queue()
      ...

  Returns:
    The return value of multiprocessing.Manager()
  """
    # Use a short directory in /tmp. Do not use /tmp directly to keep these
    # temperary files together and because certain environments do not like too
    # many top-level paths in /tmp (see crbug.com/945523).
    # Make it mode 1777 to mirror /tmp, so that we don't have failures when root
    # calls parallel first, and some other user calls it later.
    tmp_dir = '/tmp/chromite.parallel.%d' % os.geteuid()
    osutils.SafeMakedirs(tmp_dir, mode=0o1777)
    old_tempdir_value, old_tempdir_env = osutils.SetGlobalTempDir(tmp_dir)
    try:
        m = HackTimeoutSyncManager()
        # SyncManager doesn't handle KeyboardInterrupt exceptions well; pipes get
        # broken and E_NOENT or E_PIPE errors are thrown from various places. We
        # can just ignore SIGINT in the SyncManager and things will close properly
        # when the enclosing with-statement exits.
        m.start(IgnoreSigintAndSigterm)
        return m
    finally:
        osutils.SetGlobalTempDir(old_tempdir_value, old_tempdir_env)
コード例 #3
0
 def testLongTempDirectory(self):
   """Test that we can handle a long temporary directory."""
   with osutils.TempDir() as tempdir:
     new_tempdir = os.path.join(tempdir, 'xxx/' * 100)
     osutils.SafeMakedirs(new_tempdir)
     old_tempdir, old_tempdir_env = osutils.SetGlobalTempDir(new_tempdir)
     try:
       self.testParallelHelloWorld()
     finally:
       osutils.SetGlobalTempDir(old_tempdir, old_tempdir_env)
コード例 #4
0
ファイル: parallel.py プロジェクト: smrhein/PyTBB
def Manager():
    """Create a background process for managing interprocess communication.

    This manager wraps multiprocessing.Manager() and ensures that any sockets
    created during initialization are created in '/tmp' rather than in a custom
    temp directory. This is needed because TMPDIR might be really long, and
    named sockets are limited to 108 characters.

    Usage:
        with Manager() as manager:
            queue = manager.Queue()
            ...

    Returns:
        The return value of multiprocessing.Manager()
    """
    old_tempdir_value, old_tempdir_env = osutils.SetGlobalTempDir('/tmp')
    try:
        return multiprocessing.Manager()
    finally:
        osutils.SetGlobalTempDir(old_tempdir_value, old_tempdir_env)