Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _init_multicast_endpoint(self):
multicast_addr, multicast_port = urlparse(self.multicast_endpoint)\
.netloc.split(':')
try:
self.udp_socket = create_udp_socket(multicast_addr,
multicast_port)
self.loop.add_handler(self.udp_socket.fileno(),
self.handle_autodiscover_message,
ioloop.IOLoop.READ)
except (IOError, OSError, ValueError):
message = ("Multicast discovery is disabled, there was an "
"error during udp socket creation.")
logger.warning(message, exc_info=True)
bool)
elif opt.startswith('hooks.'):
hook_name = opt[len('hooks.'):]
val = [elmt.strip() for elmt in val.split(',', 1)]
if len(val) == 1:
val.append(False)
else:
val[1] = to_boolean(val[1])
watcher['hooks'][hook_name] = val
elif opt == 'respawn':
watcher['respawn'] = dget(section, "respawn", True, bool)
elif opt == 'env':
logger.warning('the env option is deprecated the use of '
'env sections is recommended')
watcher['env'] = parse_env_str(val)
elif opt == 'autostart':
watcher['autostart'] = dget(section, "autostart", True,
bool)
elif opt == 'close_child_stdout':
watcher['close_child_stdout'] = dget(section,
"close_child_stdout",
False, bool)
elif opt == 'close_child_stderr':
watcher['close_child_stderr'] = dget(section,
"close_child_stderr",
False, bool)
else:
# freeform
# stream stderr/stdout if configured
if self.stream_redirector:
self.stream_redirector.add_redirections(process)
self.processes[process.pid] = process
logger.debug('running %s process [pid %d]', self.name,
process.pid)
if not self.call_hook('after_spawn', pid=process.pid):
self.kill_process(process)
del self.processes[process.pid]
return False
# catch ValueError as well, as a misconfigured rlimit setting could
# lead to bad infinite retries here
except (OSError, ValueError) as e:
logger.warning('error in %r: %s', self.name, str(e))
if process is None:
nb_tries += 1
continue
else:
self.notify_event("spawn", {"process_pid": process.pid,
"time": process.started})
return process.started
return False
# stream stderr/stdout if configured
if pipe_stdout:
self.stdout_redirector.add_redirection('stdout',
process,
process.stdout)
if pipe_stderr:
self.stderr_redirector.add_redirection('stderr',
process,
process.stderr)
self.processes[process.pid] = process
logger.debug('running %s process [pid %d]', self.name,
process.pid)
except OSError, e:
logger.warning('error in %r: %s', self.name, str(e))
if process is None:
nb_tries += 1
continue
else:
self.notify_event("spawn", {"process_pid": process.pid,
"time": time.time()})
time.sleep(self.warmup_delay)
return
self.stop()
differences.append('host={0}'.format(self.host))
if port != self.port:
differences.append('port={0}'.format(self.port))
if backlog != self.backlog:
differences.append('backlog={0}'.format(self.backlog))
if path != self.path:
differences.append('path={0}'.format(self.path))
if umask != self.umask:
differences.append('umask={0}'.format(self.umask))
if interface != self.interface:
differences.append('interface={0}'.format(self.interface))
if so_reuseport != self.so_reuseport:
differences.append('so_reuseport={0}'.format(
self.so_reuseport))
if differences:
logger.warning('Socket "%s" already exists in papa with '
'%s. Using the existing socket.',
name, ' '.join(differences))
self.replace = True
if not p['running']:
self._papa.remove_processes(papa_name)
try:
p = self._papa.make_process(papa_name,
executable=self.executable, args=args,
env=self.env,
working_dir=self.working_dir,
uid=self.uid, gid=self.gid,
rlimits=self.rlimits,
stdout=stdout, stderr=stderr)
except papa.Error:
p = self._papa.list_processes(papa_name)
if p:
p = p[papa_name]
logger.warning('Process "%s" wid "%d" already exists in papa. '
'Using the existing process.',
self.name, self.wid)
else:
raise
self._worker = PapaProcessWorker(self, p['pid'])
self._papa_watcher = self._papa.watch_processes(papa_name)
self.started = p['started']