本文整理汇总了Python中os.sync方法的典型用法代码示例。如果您正苦于以下问题:Python os.sync方法的具体用法?Python os.sync怎么用?Python os.sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.sync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disrupt
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def disrupt(self):
L.describe('Set the DNS servers in resolv.conf to public DNS servers')
temp_resolv_conf = open(self._temp_resolv_conf_path, "w")
# TODO: make configurable?
dns_servers = ['37.235.1.174', '37.235.1.177']
for nameserver in dns_servers:
temp_resolv_conf.write("nameserver {}\n".format(nameserver))
temp_resolv_conf.close()
if os.path.islink(self._resolv_conf_path) and os.path.exists(self._resolv_conf_path):
self._resolv_conf_target_path = os.readlink(self._resolv_conf_path)
os.remove(self._resolv_conf_path)
os.symlink(self._temp_resolv_conf_path, self._resolv_conf_path)
os.sync()
else:
raise XVEx("Can't replace resolv.conf; not a symlink")
示例2: download
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def download(self, make_dest_dir=True):
with self.ftpc() as ftpc:
if self.exists():
# if the dest path does not exist
if make_dest_dirs:
os.makedirs(os.path.dirname(
self.local_path, exists_ok=True))
try:
ftpc.syncronize_times()
except:
pass
ftpc.download(source=self.remote_path, target=self.local_path)
os.sync()
else:
raise FTPFileException(
"The file does not exist remotely: %s" % self.local_file())
示例3: delete_item
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def delete_item(item_path):
failed = 0
while os.path.exists(item_path):
try:
shutil.rmtree(item_path)
except Exception as e:
print("TryDelete failed!")
print("Item: ", item_path)
print("Stat: ", os.stat(item_path))
failed += 1
if failed > 20:
print("Deletion failed!")
return
# You need an explicit sync call or the load_zips call can sometimes miss the new files.
# Yes, this was actually an issue.
os.sync()
time.sleep(0.1 * failed)
# Force the destructors to run in case we have the handle open still, somehow.
gc.collect()
os.stat(item_path)
if not os.path.exists(item_path):
return
示例4: __init__
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def __init__(self, tableName = None, load_database = True, *args, **kwargs):
if tableName:
self.tableName = self.tableName+"_"+tableName
super().__init__(*args, **kwargs)
self.hasher = TestHasher()
if load_database:
self.copy_zips()
self.log.info("sync()ing")
# You need an explicit sync call or the load_zips call can sometimes miss the new files.
# Yes, this was actually an issue.
os.sync()
self.load_zips(TEST_ZIP_PATH)
# Since the tree deliberately persists (it's a singleton), we have to /explicitly/ clobber it.
self.unlocked_doLoad()
示例5: __enter__
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def __enter__(self):
if not self.is_relevant:
return
self.assert_no_access()
try:
gen.log("Unmounting %s" % self.usb_disk)
os.sync() # This is needed because UDISK.unmount() can timeout.
UDISKS.unmount(self.usb_disk)
except dbus.exceptions.DBusException as e:
gen.log("Unmount of %s has failed." % self.usb_disk)
# This may get the partition mounted. Don't call!
# self.exit_callback(details(self.usb_disk))
raise UnmountError(e)
gen.log("Unmounted %s" % self.usb_disk)
return self
示例6: __exit__
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def __exit__(self, type_, value, traceback_):
if not self.is_relevant:
return
os.sync() # This should not be strictly necessary
time.sleep(1) # Yikes, mount always fails without this sleep().
try:
mount_point = UDISKS.mount(self.usb_disk)
config.add_remounted(self.usb_disk)
self.exit_callback(details(self.usb_disk))
except dbus.exceptions.DBusException as e:
raise MountError(e)
gen.log("Mounted %s" % (self.usb_disk))
示例7: maybe_mkdir
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def maybe_mkdir(path):
try:
os.mkdir(path)
except:
pass
if not simulator:
os.sync()
# path to store #reckless entropy
示例8: sync
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def sync():
try:
os.sync()
except:
pass
示例9: _restore_dns_servers
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def _restore_dns_servers(self):
os.remove(self._resolv_conf_path)
os.symlink(self._resolv_conf_target_path, self._resolv_conf_path)
os.sync()
示例10: download
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def download(self, bucket_name, key, file_dir):
self._S3object.remote_download(bucket_name, key, file_dir)
os.sync() # ensure flush to disk
return file_dir
示例11: download
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def download(self, make_dest_dir=True):
with self.sftpc() as sftpc:
if self.exists():
# if the dest path does not exist
if make_dest_dirs:
os.makedirs(os.path.dirname(
self.local_path, exists_ok=True))
sftpc.get(remotepath=self.remote_path,
localpath=self.local_path, preserve_mtime=True)
os.sync()
else:
raise SFTPFileException(
"The file cannot be parsed as an STFP path in "
"form 'host:port/path/to/file': %s" % self.local_file())
示例12: download
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def download(self, container_name, blob_name, file_dir):
self._Azureobject.remote_download(container_name, blob_name, file_dir)
os.sync() # ensure flush to disk
return file_dir
示例13: download
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def download(self, bucket_name, key, file_dir):
self._GCobject.remote_download(bucket_name, key, file_dir)
os.sync()
return file_dir
示例14: shutdown
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def shutdown(self):
'''Call the dbus proxy to start the shutdown.'''
if self._proxy:
os.sync()
self._proxy(*self._args)
示例15: save_obj
# 需要导入模块: import os [as 别名]
# 或者: from os import sync [as 别名]
def save_obj(obj, name):
# print("Saving %s" % name)
with open(name, 'wb') as f:
pickle.dump(obj=obj, file=f)
# os.sync()