Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.ctx.controls["config"].upgrade(None, config)
finally:
config.close()
self.ctx.err("Creating %s" % cfg_xml)
cfg_tmp.rename(str(cfg_xml))
try:
try:
config = omero.config.ConfigXml(str(cfg_xml))
except Exception, e:
self.ctx.die(577, str(e))
if config.save_on_close:
config.save()
else:
self.ctx.err("%s read-only" % cfg_xml)
except portalocker.LockException:
try:
config.close()
except:
pass
self.ctx.die(111, "Could not acquire lock on %s" % cfg_xml)
return config
info = get_tls_from_payload(payload, is_key)
pem_file_path = get_tls_full_path(root_dir, TLS.DIR_KEYS_CERTS if is_key else TLS.DIR_CA_CERTS, info)
pem_file = open(pem_file_path, 'w')
try:
portalocker.lock(pem_file, portalocker.LOCK_EX)
pem_file.write(payload)
pem_file.close()
os.chmod(pem_file_path, 0o640)
return pem_file_path
except portalocker.LockException:
pass # It's OK, something else is doing the same thing right now
current_name = current.name
current_ident = current.ident
contents = self.lock_template.format(
pid, current_name, current_ident, _utcnow().isoformat(), self.os_user_name,
)
self.tmp_file.write(contents.encode('utf8'))
self.tmp_file.flush()
if _has_debug:
logger.debug('Created lock file `%s` (%s %s %s)', self.tmp_file_name, pid, current_name, current_ident)
try:
lock(self.tmp_file, _flags)
except LockException:
return False
else:
return True
f.write(yaml.safe_dump(test_data, default_flow_style=False, allow_unicode=True))
print "Starting new combination in %s" % comb_directory
# Decide statistics location
stats_filename = os.path.join(comb_directory, str(seed) + ".csv")
log_filename = os.path.join(comb_directory, str(seed) + "_vebose.log")
# Check whether these stats have already been produced...
if os.path.isfile(stats_filename):
print "%s found, skipping." % stats_filename
continue
# ... or are being produced right now
lock_filename = stats_filename + ".lock"
lock_file = open(lock_filename, "a")
try:
portalocker.lock(lock_file, portalocker.LOCK_EX | portalocker.LOCK_NB)
except portalocker.LockException:
print "%s being produced, skipping." % stats_filename
lock_file.close()
continue;
if precmd:
seeded_precmd = precmd.replace("$seed", str(seed))
print "Running pre-command %s" % seeded_precmd
subprocess.call(seeded_precmd, shell=True, cwd=new_directory)
print "Running MicroGP to produce %s..." % stats_filename
stats_filename_temp = str(seed) + time.strftime("_%Y-%m-%d,%H:%M:%S") + ".csv"
if os.path.isfile(os.path.join(new_directory, stats_filename_temp)):
os.remove(os.path.join(new_directory, stats_filename_temp))
process = subprocess.Popen([
os.path.abspath(ugp),
'--randomSeed', str(seed),
'--log', 'verbose.log', 'verbose', 'brief',
'--statisticsPathName', str(stats_filename_temp)],
_logger.debug("Hook executing with configured wake ups: %s", wakeups)
wakeup_at = execute_wakeups(
wakeups, datetime.datetime.now(datetime.timezone.utc), _logger
)
_logger.debug("Hook next wake up at %s", wakeup_at)
if wakeup_at:
wakeup_at -= datetime.timedelta(seconds=wakeup_delta)
_logger.info("Scheduling next wake up at %s", wakeup_at)
wakeup_fn(wakeup_at)
else:
_logger.info("No wake up required. Terminating")
# create the just woke up file
pathlib.Path(woke_up_file).touch()
except portalocker.LockException:
_logger.warning(
"Hook unable to acquire lock. Not informing daemon.", exc_info=True
)
try:
# exclusive non-blocking lock
portalocker.lock(lock_file, portalocker.LOCK_EX | portalocker.LOCK_NB)
# got the lock, let's write our PID into it:
lock_file.write("%d\n" % os.getpid())
lock_file.flush()
self._acquired_lock = True
self.gpu_id = gpu_id
self.lock_file = lock_file
self.lockfile_path = lockfile_path
logger.info("Acquired GPU {}.".format(gpu_id))
return gpu_id
except portalocker.LockException as e:
# portalocker packages the original exception,
# we dig it out and raise if unrelated to us
if e.args[0].errno != errno.EAGAIN: # pylint: disable=no-member
logger.error("Failed acquiring GPU lock.", exc_info=True)
raise e.args[0]
else:
logger.debug("GPU {} is currently locked.".format(gpu_id))
return None