Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(self):
while 1:
hdrs, payload = childutils.listener.wait(self.stdin, self.stdout)
self.handle_event(hdrs, payload)
childutils.listener.ok(self.stdout)
def main(max):
start = time.time()
report = open('/tmp/report', 'w')
i = 0
while 1:
childutils.pcomm.stdout('the_data')
sys.stdin.readline()
report.write(str(i) + ' @ %s\n' % childutils.get_asctime())
report.flush()
i+=1
if max and i >= max:
end = time.time()
report.write('%s per second\n' % (i / (end - start)))
sys.exit(0)
def _wait_for_supervisor_event(self):
"""Wait for supervisor events.
"""
childutils.listener.ready(sys.stdout)
while not self._stop_event.is_set():
try:
rdfs, _, _ = select.select([sys.stdin], [], [], .5)
except InterruptedError:
continue
if rdfs:
headers = childutils.get_headers(rdfs[0].readline())
# Read the payload to make read buffer empty.
_ = sys.stdin.read(int(headers['len']))
event_type = headers[EVENT_NAME_KEY]
self._log('Received %s event from supervisor', event_type)
return event_type
def get_process_state_change_msg(self, headers, payload):
pheaders, pdata = childutils.eventdata(payload+'\n')
if int(pheaders['expected']):
return None
self.add_customized_mail_list(pheaders)
txt = 'Process %(groupname)s:%(processname)s (pid %(pid)s) died \
unexpectedly' % pheaders
return '%s -- http://%s:%d -- %s' % (childutils.get_asctime(self.now),
self.local_ip, self.supervisord_port, txt)
def get_process_state_change_msg(self, headers, payload):
pheaders, pdata = childutils.eventdata(payload+'\n')
if int(pheaders['expected']):
return None
txt = 'Process %(groupname)s:%(processname)s (pid %(pid)s) died \
unexpectedly' % pheaders
return '%s -- %s' % (childutils.get_asctime(self.now), txt)
@cli.command('stop')
def stop():
"""
Stop daemon along with any tunnels that are running
"""
try:
childutils.getRPCInterface({'SUPERVISOR_SERVER_URL':'unix:///tmp/vpnsupervisor.sock'}).supervisor.shutdown()
except Exception as e:
if not 'No such' in str(e):
raise
else:
print 'Supervisor does not appear to be running'
return
print('Supervisor stopped')
def _wait_for_supervisor_event(self):
"""Wait for supervisor events.
"""
childutils.listener.ready(sys.stdout)
while not self._stop_event.is_set():
try:
rdfs, _, _ = select.select([sys.stdin], [], [], .5)
except InterruptedError:
continue
if rdfs:
headers = childutils.get_headers(rdfs[0].readline())
# Read the payload to make read buffer empty.
_ = sys.stdin.read(int(headers['len']))
event_type = headers[EVENT_NAME_KEY]
self._log('Received %s event from supervisor', event_type)
return event_type
raise AboutToShutdown