def asyncWrite(self):
        """
        A function to write files asynchronously to the job store such that subsequent jobs are
        not delayed by a long write operation.
        """
        try:
            while True:
                try:
                    # Block for up to two seconds waiting for a file
                    args = self.queue.get(timeout=2)
                except Empty:
                    # Check if termination event is signaled
                    # (set in the event of an exception in the worker)
                    if self._terminateEvent.isSet():
                        raise RuntimeError("The termination flag is set, exiting")
                    continue
                # Normal termination condition is getting None from queue
                if args is None:
                    break
                inputFileHandle, jobStoreFileID = args
                cachedFileName = self.encodedFileID(jobStoreFileID)
                # Ensure that the harbinger exists in the cache directory and that the PID
                # matches that of this writing thread.
                # If asyncWrite is ported to subprocesses instead of threads in the future,
                # insert logic here to securely overwrite the harbinger file.
                harbingerFile = self.HarbingerFile(self, cachedFileName=cachedFileName)
                assert harbingerFile.exists()
                assert harbingerFile.read() == int(os.getpid())
                # We pass in a fileHandle, rather than the file-name, in case
                # the file itself is deleted. The fileHandle itself should persist
                # while we maintain the open file handle
                with self.jobStore.updateFileStream(jobStoreFileID) as outputFileHandle:
                    shutil.copyfileobj(inputFileHandle, outputFileHandle)
                inputFileHandle.close()
                # Remove the file from the lock files
                with self._pendingFileWritesLock:
                    self._pendingFileWrites.remove(jobStoreFileID)
                # Remove the harbinger file
                harbingerFile.delete()
        except:
            self._terminateEvent.set()
            raise
def asyncWrite ( self ) : try : while True : try : args = self . queue . get ( timeout = 2 ) except Empty : if self . _terminateEvent . isSet ( ) : raise RuntimeError ( "The termination flag is set, exiting" ) continue if args is None : break inputFileHandle , jobStoreFileID = args cachedFileName = self . encodedFileID ( jobStoreFileID ) harbingerFile = self . HarbingerFile ( self , cachedFileName = cachedFileName ) assert harbingerFile . exists ( ) assert harbingerFile . read ( ) == int ( os . getpid ( ) ) with self . jobStore . updateFileStream ( jobStoreFileID ) as outputFileHandle : shutil . copyfileobj ( inputFileHandle , outputFileHandle ) inputFileHandle . close ( ) with self . _pendingFileWritesLock : self . _pendingFileWrites . remove ( jobStoreFileID ) harbingerFile . delete ( ) except : self . _terminateEvent . set ( ) raise
A function to write files asynchronously to the job store such that subsequent jobs are
        not delayed by a long write operation.