當前位置: 首頁>>代碼示例>>Python>>正文


Python os.fsync方法代碼示例

本文整理匯總了Python中os.fsync方法的典型用法代碼示例。如果您正苦於以下問題:Python os.fsync方法的具體用法?Python os.fsync怎麽用?Python os.fsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.fsync方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: saveToDisk

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def saveToDisk(self):
        """Saves the data to disk."""
        out.info('Saving to disk (%s)\n' % (self.filename))

        # Make sure they want to save
        if(not self.attrSaveable()):
            return

        # Get whatever the data is
        pyld = self.exportAttr(self.getAttr())

        # Write the file to disk, truncate if it exists
        try:
            with open(self.filename, 'wb') as output:
                pickle.dump(pyld, output)
                os.fsync(output.fileno())
        except Exception as e:
            out.err('Error writing to disk %s\n' % (str(e)))

        try:
            with open(self.filename + ".yaml", "w") as output:
                yaml.dump(pyld, output)
        except Exception as error:
            out.err("Error writing yaml file: {}".format(error)) 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:26,代碼來源:pd_storage.py

示例2: stop_recording

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def stop_recording(self):

		"""Stops data recording
		"""

		# consolidate the data file on the hard drive
		# internal buffer to RAM
		self._logfile.flush()
		# RAM file cache to disk
		os.fsync(self._logfile.fileno())

		# set self._logdata to False, so the data processing thread does not
		# write samples to the log file
		if self._logdata:
			self.log_message("stop_recording")
			self._logdata = False 
開發者ID:esdalmaijer,項目名稱:PyTribe,代碼行數:18,代碼來源:pytribe.py

示例3: _log_header

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def _log_header(self):

		"""Logs a header to the data file
		"""

		# write a header to the data file
		header = self._separator.join(['timestamp','time','fix','state',
								'rawx','rawy','avgx','avgy','psize',
								'Lrawx','Lrawy','Lavgx','Lavgy','Lpsize','Lpupilx','Lpupily',
								'Rrawx','Rrawy','Ravgx','Ravgy','Rpsize','Rpupilx','Rpupily'
								])
		self._logfile.write(header + '\n') # to internal buffer
		self._logfile.flush() # internal buffer to RAM
		os.fsync(self._logfile.fileno()) # RAM file cache to disk
		self._firstlog = False



# # # # # #
# PARALLEL ClASS


# Ugly, but sod it: A global variable for the most recent sample. 
開發者ID:esdalmaijer,項目名稱:PyTribe,代碼行數:25,代碼來源:pytribe.py

示例4: test_schema_txt_to_feature_spec

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def test_schema_txt_to_feature_spec(self):
        schema_txt = """
            feature {
                name: "test_feature"
                value_count {
                    min: 1
                    max: 1
                }
                type: FLOAT
                presence {
                    min_count: 1
                }
            }
        """.encode("utf-8")

        with NamedTemporaryFile() as f:
            f.write(schema_txt)
            f.flush()
            os.fsync(f)
            feature_spec = schema_txt_file_to_feature_spec(f.name)
            self.assertEqual(feature_spec, {"test_feature": tf.VarLenFeature(dtype=tf.float32)}) 
開發者ID:spotify,項目名稱:spotify-tensorflow,代碼行數:23,代碼來源:tf_schema_utils_test.py

示例5: flush

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def flush(self, fsync=False):
        """
        Force all buffered modifications to be written to disk.

        Parameters
        ----------
        fsync : bool (default False)
          call ``os.fsync()`` on the file handle to force writing to disk.

        Notes
        -----
        Without ``fsync=True``, flushing may not guarantee that the OS writes
        to disk. With fsync, the operation will block until the OS claims the
        file has been written; however, other caching layers may still
        interfere.
        """
        if self._handle is not None:
            self._handle.flush()
            if fsync:
                try:
                    os.fsync(self._handle.fileno())
                except OSError:
                    pass 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:pytables.py

示例6: test_write

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def test_write(self):
        with gzip.GzipFile(self.filename, 'wb') as f:
            f.write(data1 * 50)

            # Try flush and fileno.
            f.flush()
            f.fileno()
            if hasattr(os, 'fsync'):
                os.fsync(f.fileno())
            f.close()

        # Test multiple close() calls.
        f.close()

    # The following test_write_xy methods test that write accepts
    # the corresponding bytes-like object type as input
    # and that the data written equals bytes(xy) in all cases. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:test_gzip.py

示例7: flush

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def flush(self, fsync=False):
        """
        Force all buffered modifications to be written to disk.

        Parameters
        ----------
        fsync : bool (default False)
          call ``os.fsync()`` on the file handle to force writing to disk.

        Notes
        -----
        Without ``fsync=True``, flushing may not guarantee that the OS writes
        to disk. With fsync, the operation will block until the OS claims the
        file has been written; however, other caching layers may still
        interfere.
        """
        if self._handle is not None:
            self._handle.flush()
            if fsync:
                try:
                    os.fsync(self._handle.fileno())
                except:
                    pass 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:25,代碼來源:pytables.py

示例8: json_writer

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def json_writer():
   # schreibt ein JSON-Logfile
   if options.verbose:
       print('Starting JSON writer Task')
   if options.fahrenheit:
      unit = '°F'
   else:
      unit = '°C'
   while True:
      item_time, chksum_is, type, temp1, temp2 =  json_queue.get()
      set = {'time': item_time, 'checksum': chksum_is, 'type' : type, 'unit': unit, 'temperature_1' : temp1, 'temperature_2' : temp2}
      if options.noappend:
        tmp_filename = get_random_filename(options.json)
        with open(tmp_filename, 'w') as json_file:
            json_file.write(json.dumps(set))
            json_file.flush()
            os.fsync(json_file.fileno())
            json_file.close()
            os.rename(tmp_filename, options.json)
      else:
        with open(options.json, 'a') as json_file:
            json_file.write(json.dumps(set) + ',')
            json_file.flush()

      json_queue.task_done() 
開發者ID:WLANThermo,項目名稱:WLANThermo_v2,代碼行數:27,代碼來源:maverick.py

示例9: config_write

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def config_write(configfile, config, oldconfig):
    # Schreibt das Configfile
    # Ein Lock sollte im aufrufenden Programm gehalten werden!

    tmp_filename = get_random_filename(configfile)
    with codecs.open(tmp_filename, 'w', 'utf_8') as new_ini:
        for section_name in config.sections():
            new_ini.write(u'[{section_name}]\n'.format(section_name=section_name))
            for (key, value) in config.items(section_name):
                try:
                    new_ini.write(u'{key} = {value}\n'.format(key=key, value=update_settings(section_name, key, oldconfig.get(section_name, key))))
                except (configparser.NoSectionError, configparser.NoOptionError):
                    new_ini.write(u'{key} = {value}\n'.format(key=key, value=value))
            new_ini.write('\n')
        new_ini.flush()
        os.fsync(new_ini.fileno())
        new_ini.close()
        os.rename(tmp_filename, configfile) 
開發者ID:WLANThermo,項目名稱:WLANThermo_v2,代碼行數:20,代碼來源:wlt_2_updateconfig.py

示例10: write_text_file

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def write_text_file(self, path, data, atomic=False, mode="w"):
        self.create_parent_folder(path)

        if atomic:
            with self.open_atomic(path, mode) as file:
                file.write(data)
        else:
            from a2ml.api.utils import fsclient
            self.remove_file(path)

            with fsclient.open_file(path, mode) as file:
                try:
                    file.write(data)
                finally:
                    file.flush()  # flush file buffers
                    os.fsync(file.fileno())

        self.read_text_file(path) 
開發者ID:augerai,項目名稱:a2ml,代碼行數:20,代碼來源:local_fsclient.py

示例11: open_atomic

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def open_atomic(self, path, mode):
        parent = self.get_parent_folder(os.path.abspath(path))
        self.list_folder(parent)

        temp_dir = self.get_temp_folder()
        try:
            temp_path = os.path.join(temp_dir, os.path.basename(path))
            with open(temp_path, mode) as f:
                try:
                    yield f
                finally:
                    f.flush()  # flush file buffers
                    os.fsync(f.fileno())  # ensure all data are written to disk
            if platform.system() == "Windows":
                if os.path.exists(path):
                    os.remove(path)

            os.rename(temp_path, path)  # atomic move to target place
        finally:
            self.remove_folder(temp_dir) 
開發者ID:augerai,項目名稱:a2ml,代碼行數:22,代碼來源:local_fsclient.py

示例12: atomic_write

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def atomic_write(filepath, binary=False, fsync=False):
    """ Writeable file object that atomically updates a file (using a temporary file). In some cases (namely Python < 3.3 on Windows), this could result in an existing file being temporarily unlinked.

    :param filepath: the file path to be opened
    :param binary: whether to open the file in a binary mode instead of textual
    :param fsync: whether to force write the file to disk
    """

    tmppath = filepath + '~'
    while os.path.isfile(tmppath):
        tmppath += '~'
    try:
        with open(tmppath, 'wb' if binary else 'w') as file:
            yield file
            if fsync:
                file.flush()
                os.fsync(file.fileno())
        replace(tmppath, filepath)
    finally:
        try:
            os.remove(tmppath)
        except (IOError, OSError):
            pass 
開發者ID:ArztSamuel,項目名稱:DRL_DeliveryDuel,代碼行數:25,代碼來源:atomic_write.py

示例13: write

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def write(self, json_dict):

        json_data = json.dumps(json_dict, indent=4, sort_keys=True)
        if self.path is None:
            return json_data

        temp_path = "%s.tmp.%s" % (self.path, os.getpid())
        with open(temp_path, "w") as f:
            f.write(json_data)
            f.flush()
            os.fsync(f.fileno())

        if os.path.exists(self.path):
            mode = os.stat(self.path).st_mode
        else:
            mode = stat.S_IREAD | stat.S_IWRITE
        try:
            os.rename(temp_path, self.path)
        except Exception:  # pylint: disable=broad-except
            os.remove(self.path)
            os.rename(temp_path, self.path)
        os.chmod(self.path, mode) 
開發者ID:lbryio,項目名稱:torba,代碼行數:24,代碼來源:wallet.py

示例14: _remove_noobs_defaults

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def _remove_noobs_defaults(self):
        """
        Remove the config entries added by Noobs,
        by removing all the lines after and including
        noobs' sentinel

        """
        lines = read_file_contents_as_lines(self.path)
        with open_locked(self.path, 'w') as boot_config_file:

            for line in lines:
                if line == noobs_line:
                    break

                boot_config_file.write(line + "\n")

            # flush changes to disk
            boot_config_file.flush()
            os.fsync(boot_config_file.fileno()) 
開發者ID:KanoComputing,項目名稱:kano-settings,代碼行數:21,代碼來源:boot_config.py

示例15: set_value

# 需要導入模塊: import os [as 別名]
# 或者: from os import fsync [as 別名]
def set_value(self, name, value=None, config_filter=Filter.ALL):
        # if the value argument is None, the option will be commented out
        lines = read_file_contents_as_lines(self.path)
        if not lines:  # this is true if the file is empty, not sure that was intended.
            return

        logger.info('writing value to {} {} {}'.format(self.path, name, value))

        config = BootConfigParser(lines)
        config.set(name, value, config_filter=config_filter)

        with open_locked(self.path, "w") as boot_config_file:
            boot_config_file.write(config.dump())

            # flush changes to disk
            boot_config_file.flush()
            os.fsync(boot_config_file.fileno()) 
開發者ID:KanoComputing,項目名稱:kano-settings,代碼行數:19,代碼來源:boot_config.py


注:本文中的os.fsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。