当前位置: 首页>>代码示例>>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;未经允许,请勿转载。