def __str__(self): '''get execution name - to be used for log filename Components: - Number atoms - Volume - Spacegroup number - Functional name ''' if self.name is None: self.name = '{}_{}_{}_{}'.format( len(self.atoms), int(self.atoms.get_volume() * 100), self.spacegroup, self.functional) _gpaw = os.environ['GPAW'] _pwd = os.environ['PWD'] self.procname = '{} ({})'.format(self.name, _pwd.replace(_gpaw + '/', '')) setproctitle(self.procname) return self.name
def takeuptime(n): setproctitle(getproctitle() + ' [' + str(n) + ']') chars = 'abcdefghijklmnopqrstuvwxyz0123456789' s = chars * 1000 for i in range(10*n): for c in chars: s.count(c)
def solutionworker(output_q,cmd_dictionary=None): # Reset default signal handlers signal.signal(signal.SIGCHLD, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL) setproctitle("fealdend: solutionworker") def _output_queue_UNKNOWN(output_request): # Process UNKNOWN messages from a solution queue logger.debug("output_queue: process (%d) reads UNKNOWN, msg is %s" % (os.getpid(), msg)) return True def _output_queue_WEBOUTPUT(output_request): # Generate output for web if output_request.status == "FOUND": # Process FOUND messages from a solution queue logger.debug("solutionworker(%d): CMD: WEBOUTPUT STAT: found on %s" % (os.getpid(), output_request.sensor)) weboutput.solution_output(output_request.sensor, output_request.scores, output_request.folds, output_request.output_dir) #email_notification(request[0], recognition, request[3]) elif output_request.status == "FAILED": weboutput.failed_output(output_request.sensor, output_request.output_dir, "Search timed out") logger.debug("solutionworker (%d): FAILED received for %s" % (os.getpid(), output_request.sensor)) else: logger.debug("solutionworker (%d): I don't know how I got here, %s" % (os.getpid(), output_request)) if not cmd_dictionary: cmd_dictionary = {'WEBOUTPUT': _output_queue_WEBOUTPUT, 'UNKNOWN': _output_queue_UNKNOWN} # We must have a function associated with "UNKNOWN" assert cmd_dictionary["UNKNOWN"] while True: output_request = output_q.get(block=True) if output_request.command in cmd_dictionary: # If the command is something we have in our # message dictionary, then call the function # associated with that command logger.debug("solutionworker(%d): going to attempt to execute %s" % (os.getpid(), cmd_dictionary[output_request.command])) cmd_dictionary[output_request.command](output_request) else: # Otherwise call the command associated # with UNKNOWN cmd_dictionary["UNKNOWN"](output_request)
def main(): setproctitle("cinnamon-calendar-server") server = CalendarServer() signal.signal(signal.SIGINT, lambda s, f: server.exit()) signal.signal(signal.SIGTERM, lambda s, f: server.exit()) server.run(sys.argv) return 0
def _maxtimewatcher(maxtime,command): """Acts as a timer. If maxtime seconds elapse, then sets command to zero""" # Reset default signal handlers signal.signal(signal.SIGCHLD, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL) setproctitle("fealdend: timewatcher(%s)" % sensor.GetRecognition()) starttime = time.time() endtime = starttime + maxtime while True: time.sleep(1) if time.time() >= endtime: logger.info("sensorsearch(...): _maxtimewatcher(%d) time exceeded, stopping search" % maxtime) command.value = 0
def _request_queue_BACKTRACKING(request, output_q): logger.debug("searchworker(%d): %s dispatched to _request_queue_BACKTRACKING" % (os.getpid(), request.recognition)) # Do the search sensor = util.Sensor(request.recognition) logger.debug("sensor.Recognition is %s" % sensor.GetRecognition()) setproctitle("fealdend: searchworker(%s)" % sensor.GetRecognition()) solutions = backtracking.sensorsearch(sensor, request.maxtime, bindingratiorange = (request.binding_ratio_lo, request.binding_ratio_hi), maxunknownpercent=request.maxunknown_percent, numfoldrange=(request.numfolds_lo,request.numfolds_hi), maxsolutions= request.numsolutions, maxenergy = request.maxenergy) logger.info("fealdend: searchworker(%s), found %d solutions, putting them " "on the queue" % (sensor.GetRecognition(), len(solutions))) setproctitle("fealdend: searchworker") if solutions: for solution in solutions: # put it on the output_q logger.debug("searchworker (%d): found solution for %s" % (os.getpid(),request.recognition)) # (FOUND/FAILED, solution, output_directory, email) output_request = util.OutputElement(command="WEBOUTPUT", request_id=request.request_id, status="FOUND", output_dir= request.output_dir, sensor = solution.sensor, scores = solution.scores, folds = solution.folds, email = request.email) if output_request.valid(): output_q.put(output_request) else: logger.info("searchworker(%d): attempted to put invalid output_request on to output_q, %s" % output_request) else: logger.debug("searchworker (%d): no solution for %s" % (os.getpid(), request.recognition)) output_request = util.OutputElement(command="WEBOUTPUT", status="FAILED", request_id=request.request_id, output_dir= request.output_dir, sensor = sensor, email = request.email) output_q.put(output_request)
def main(): setproctitle("cinnamon-calendar-server") # For debugging, this will keep the process alive instead of exiting after 10s hold = False if len(sys.argv) > 1 and sys.argv[1] == "hold": print("idle exit disabled...") hold = True server = CalendarServer(hold) signal.signal(signal.SIGINT, lambda s, f: server.exit()) signal.signal(signal.SIGTERM, lambda s, f: server.exit()) # Only pass the first argument to the GApplication - or it will # complain the IS_SERVICE flag doesn't support arguments. server.run([sys.argv[0]]) return 0
def start(request_q, numprocs=1): """start -- Starts a pool of workers to process requests for searches, another set of workers to process validate any solutions found and, if valid solutions are found to create suitable output for the web version Arguments: request_q -- a multiprocessing.Queue that will receive requests to be processed from the web application Returns: True """ # Create solution queue to act as a sink for all # of the worker processes. # (FOUND/FAILED, output_directory, email, sensor) setproctitle("fealdend") output_q = multiprocessing.Queue() # Create pool of wrappers around sensor search that will wait # on a request queue and process requests indefinitely searchworkers = [] for i in range(numprocs): logger.debug("main loop: starting searchworker %d" % i) p = multiprocessing.Process(target=searchworker, args=(request_q, output_q)) searchworkers.append(p) p.start() # Start a process to processing the output requests logger.debug("main loop: starting solutionworker") worker = multiprocessing.Process(target=solutionworker, args=(output_q,)) worker.daemon=True worker.start() return searchworkers + [worker]
0.38602199, 0.27105842, 0.36975171, 0.3356947 , 0.29899131, 0.427571 , 0.51788916, 0.44951466, 0.39356585, 0.36439674, 0.26742971, 0.25551044, 0.35201715, 0.27832718, 0.26474895, 0.39674158, 0.20057134, 0.40314698, 0.32152241, 0.32251481, 0.7005793 , 0.32659033, 0.36903805, 0.44043124, 0.37619567, 0.26611351, 0.33441713, 0.37142703, 0.32747486, 0.36805246, 0.54371176, 0.39479857, 0.3217335 , 0.36265054, 0.39174094, 0.37768692, 0.32706581, 0.49858319, 0.70680496, 0.38400332, 0.3867914 , 0.48905711, 0.27634555, 0.38944146, 0.31926371, 0.44867706, 0.25885832, 0.27855626, 0.29590959, 0.29334505, 0.61433217, 0.41676176, 0.61286827, 0.25917222, 0.31403825, 0.27545707, 0.32324647, 0.41412418, 0.19903402, 0.43076636, 0.29325771, 0.3538182 , 0.44366133, 0.47372824, 0.24468869] setproctitle('Random-Walk') DATABASE_NAME = '' #SQL Database TABLE_NAME = '' #SQL Table MODEL_CAT_LABELS = '' #Path to scene category file. #cats =pd.read_csv('/Users/teej/Downloads/placesCNN/categoryIndex_places205.csv',delimiter=" ",header=0) cats =pd.read_csv(MODEL_CAT_LABELS,delimiter=" ",header=0) f = lambda x: ": ".join(x.split('/')[2:]) cats['category']= cats['category'].map(f) app = Flask(__name__) def signal_handler(signal, frame):
def searchworker(request_q, output_q, cmd_dictionary=None): # Reset default signal handlers signal.signal(signal.SIGTERM, signal.SIG_DFL) signal.signal(signal.SIGCHLD, signal.SIG_DFL) setproctitle("fealdend: searchworker") def _request_queue_BACKTRACKING(request, output_q): logger.debug("searchworker(%d): %s dispatched to _request_queue_BACKTRACKING" % (os.getpid(), request.recognition)) # Do the search sensor = util.Sensor(request.recognition) logger.debug("sensor.Recognition is %s" % sensor.GetRecognition()) setproctitle("fealdend: searchworker(%s)" % sensor.GetRecognition()) solutions = backtracking.sensorsearch(sensor, request.maxtime, bindingratiorange = (request.binding_ratio_lo, request.binding_ratio_hi), maxunknownpercent=request.maxunknown_percent, numfoldrange=(request.numfolds_lo,request.numfolds_hi), maxsolutions= request.numsolutions, maxenergy = request.maxenergy) logger.info("fealdend: searchworker(%s), found %d solutions, putting them " "on the queue" % (sensor.GetRecognition(), len(solutions))) setproctitle("fealdend: searchworker") if solutions: for solution in solutions: # put it on the output_q logger.debug("searchworker (%d): found solution for %s" % (os.getpid(),request.recognition)) # (FOUND/FAILED, solution, output_directory, email) output_request = util.OutputElement(command="WEBOUTPUT", request_id=request.request_id, status="FOUND", output_dir= request.output_dir, sensor = solution.sensor, scores = solution.scores, folds = solution.folds, email = request.email) if output_request.valid(): output_q.put(output_request) else: logger.info("searchworker(%d): attempted to put invalid output_request on to output_q, %s" % output_request) else: logger.debug("searchworker (%d): no solution for %s" % (os.getpid(), request.recognition)) output_request = util.OutputElement(command="WEBOUTPUT", status="FAILED", request_id=request.request_id, output_dir= request.output_dir, sensor = sensor, email = request.email) output_q.put(output_request) def _request_queue_UNKNOWN(request, output_q): logger.debug("request_queue: process (%d) reads UNKNOWN, msg is %s" % (os.getpid(),request)), logger.debug("searchworker(%d): got this cmd_dict -- %s" % (os.getpid(), cmd_dictionary)) if not cmd_dictionary: cmd_dictionary = {'BACKTRACKING': _request_queue_BACKTRACKING, 'UNKNOWN': _request_queue_UNKNOWN} # We must have a function associated with "UNKNOWN" assert cmd_dictionary["UNKNOWN"] while True: request = request_q.get(block=True) logger.debug("searchworker(%d): got %s for %s" % (os.getpid(), request.command, request.recognition)) if request.command == "EXIT": logger.debug("request_queue(%d): got EXIT" % os.getpid()) break if request.command in cmd_dictionary: # If the command is something we have in our # message dictionary, then call the function # associated with that command logger.debug("request_queue(%d): going to attempt to execute %s" % (os.getpid(), cmd_dictionary[request.command])) cmd_dictionary[request.command](request, output_q) #raise cmd_dictionary[request[0]](request[1]) else: # Otherwise call the command associated # with UNKNOWN cmd_dictionary["UNKNOWN"](request, output_q)
import re import time import json import codecs import csv import sys from pymongo import MongoClient, Connection from datetime import datetime import gensim as gs import numpy as np from sklearn.naive_bayes import GaussianNB from sklearn.externals import joblib from nltk.corpus import stopwords from setproctitle import * setproctitle('Stream_Mod') ################################################################################### ####################Variables that contain the user credentials for the Twitter API access_token = "ACCESS_TOKEN" access_token_secret = "ACCESS_TOKEN_SECRET" consumer_key = "CONSUMER_KEY" consumer_secret = "CONSUMER_SECRET" #################################################################################### #################################################################################### ###############Variables that contain the user credentials for the Azure Translator client_ID = "CLIENT_ID" client_secret = "CLIENT_SECRET" ####################################################################################
from logging.handlers import RotatingFileHandler from setproctitle import * import socket import os from math import floor import chess import chess.engine from constants import * from parts import controls, board_sensor, actuator, leds import app import menu # Set process name so that it can be easily found and killed: setproctitle(cfg.PROCESS_NAME) # Create logs and saves directory: if not os.path.isdir(cfg.BASE_DIR + 'logs'): os.mkdir(cfg.BASE_DIR + 'logs') if not os.path.isdir(cfg.BASE_DIR + 'data'): os.mkdir(cfg.BASE_DIR + 'data') # Logging logging_formatter = logging.Formatter(cfg.LOGGING_FORMAT, cfg.LOGGING_DATE_FORMAT) logging_sh = logging.StreamHandler() logging_sh.setLevel(logging.DEBUG) logging_sh.setFormatter(logging_formatter)
torch.set_printoptions(precision=2, threshold=float('inf')) sys.path.append('%s/pytorch_structure2vec-master/s2v_lib' % os.path.dirname(os.path.realpath(__file__))) from embedding import EmbedMeanField, EmbedLoopyBP from util import cmd_args, load_data, create_process_name args = cmd_args if args.init_from != '': tmp = args.init_from state_dict = torch.load(args.init_from) args = state_dict['args'] args.init_from = tmp pname = create_process_name() setproctitle(pname) if not os.path.exists(args.savedir): os.makedirs(args.savedir) if not os.path.exists(args.logdir): os.makedirs(args.logdir) save_path = os.path.join(args.savedir, pname) log_path = os.path.join(args.logdir, pname + '.txt') if os.path.exists(save_path): os.system('rm -rf ' + save_path) os.makedirs(save_path) if not args.print: f = open(log_path, 'a+') sys.stderr = f sys.stdout = f
def checknode(sensor, depth, recognition_q, command): # Reset default signal handlers signal.signal(signal.SIGCHLD, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL) setproctitle("fealden: checknode(%s)" % sensor.GetRecognition()) checknode_logger = logging.getLogger('fealden.backtracking.checknode') # Order is important here, since we do a depth first # search. guesses = ["C","A","G","T"] # Backtracking algorithms consist of two parts, the first is to # determine if a node is "promising", that is, does it contain any # characterstics that would preclude *all* of the children of that # node from containing valid solutions. # If a node is promising, it does not imply that the node is a # condidate solution. Likewise, if a node is a candidate # solution, it may not be a candidate solution. # Send message indicating what depth we've arrived at recognition_q.put(SolutionElement(command="DEPTH", depth=depth)) # Check command queue #checknode_logger.debug(" checknode(%s, %d): command is %d" % (sensor,command.value) if command.value == 0: checknode_logger.info(" checknode(%s, %d): command is 0, returning True" % (sensor, depth)) return True # checknode_logger.debug("backtracking.checknode(%s): this worker is checking its %d node" % # (sensor, nodecounter.value())) #checknode_logger.debug(" checknode(%s, %d): StemEnergy (%f), RecognitionEnergy - 2.0 (%f)" % # (sensor, depth, sensor.StemEnergy(), sensor.RecognitionEnergy() - 2.0)) if (sensor.StemEnergy() > sensor.RecognitionEnergy() - 2.0): # Node is still promising checknode_logger.debug(" checknode(%s,%d): PROMISING" % (sensor, depth)) # Check each child of this node and append any valid solutions # from those children for guess in guesses: checknode_logger.debug(" checknode(%s,%d): checking guess %s" % (sensor, depth, guess)) # Create new sensor with this guess and recursively check # for solutions new_sensor = copy.deepcopy(sensor) new_sensor.GuessStems(guess) checknode(new_sensor, depth + 1, recognition_q, command) else: # Node is not promising, prune the tree here. recognition_q.put(SolutionElement(command="PRUNED", depth=depth)) checknode_logger.debug(" checknode(%s,%d): PRUNED" % (sensor, depth)) # At each node we visit, we will score the sensor and generate # all of its foldings and put those scores on recognition queue # where another process can evaluate them. folds = unafold.parse_ct(unafold.run_hybrid_ss_min(sensor)) scores = unafold.score_sensor(sensor,folds) recognition_q.put(SolutionElement(command="SOLUTION", sensor=sensor, scores=scores, folds=folds)) return True
#!/usr/bin/env python import pyglet from pyglet.gl import * from setproctitle import * window = pyglet.window.Window() setproctitle('road-demo') start = 0, 0 end = window.get_size() @window.event def on_draw(): window.clear() glColor3f(1.0, 0.5, 0) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_LINE_SMOOTH); glLineWidth(3) pyglet.graphics.draw(2, GL_LINES, ('v2i', start + end)) @window.event def on_mouse_drag(x, y, dx, dy, button, modifiers): global start, end if button == pyglet.window.mouse.LEFT: start = (x, y)
def worker_initialization(): setproctitle('compmake: worker just created') # http://stackoverflow.com/questions/1408356 # XXX: temporary looking at interruptions signal.signal(signal.SIGINT, signal.SIG_IGN)
# Change the name to reflect device dev_path = 'http://192.168.1.50' hv = sc.UvaBias(dev_path) context = zmq.Context() data_sck = context.socket(zmq.PUB) tree_sck = context.socket(zmq.PUB) msg_sck = context.socket(zmq.SUB) data_sck.connect(conf['data_port']) tree_sck.connect(conf['tree_port']) msg_sck.connect(conf['msg_port']) msg_sck.setsockopt(zmq.SUBSCRIBE, key) # Set the process name setproctitle(conf['worker_name']) time.sleep(0.005) # Ask to create a tree tree_sck.send(':'.join(['TREE', key, name, branch_vars, '__EOM__\0'])) time_last = time.time() while (True): if (msg_sck.poll(timeout=100) != 0): print "Asking to create tree." # This happens if the device pushes data before creating a tree. msg = msg_sck.recv()
import sys import json import redis import signal from threading import Thread from flask import Flask, render_template, request, abort, make_response, Response, jsonify from pymongo import Connection from bson import json_util from setproctitle import * setproctitle('SentiMap') DATABASE_NAME = 'streamer' TWEET_COLLECTION = 'tweets' #Redis Instance red = redis.StrictRedis() def signal_handler(signal, frame): print 'You pressed Ctrl+C!' sys.exit(0) #Function to publish all tweets in Database def publisher_thread(): print "Initializing Publisher..." db = Connection().streamer coll = db.tweets cursor = coll.find({},{"_id" : 0, "time": 0},tailable=True,timeout=False) ci=0
import re import time import json import codecs import csv import sys from pymongo import MongoClient, Connection from datetime import datetime import gensim as gs import numpy as np from sklearn.naive_bayes import GaussianNB from sklearn.externals import joblib from nltk.corpus import stopwords from setproctitle import * setproctitle('Stream_Mod') ################################################################################### ####################Variables that contain the user credentials for the Twitter API access_token = "ACCESS_TOKEN" access_token_secret = "ACCESS_TOKEN_SECRET" consumer_key = "CONSUMER_KEY" consumer_secret = "CONSUMER_SECRET" #################################################################################### #################################################################################### ###############Variables that contain the user credentials for the Azure Translator client_ID = "CLIENT_ID" client_secret="CLIENT_SECRET" ####################################################################################
global_step = 0 best_psnr = -100 best_gen_loss = 10000 best_disc_loss = 10000 args = parser.parse_args() args.__dict__['upscale_factor'] = 4 #args.traindir=globals()[args.traindir] args.valdir = globals()[args.valdir] args.__dict__['model_base_name'] = 'SRGAN_v%g_w%g_%s' % ( args.lr, args.weight, args.optim) + ('_fixG' if args.fixG else '') + ( '_fixD' if args.fixD else '') + ('_separate' if args.separate else '') args.__dict__['model_name'] = args.model_base_name + '.pth' args.__dict__['snapshot'] = 'snapshot_' + args.model_base_name setproctitle(args.model_base_name) if not os.path.exists(args.logdir): os.makedirs(args.logdir) if not os.path.exists(args.snapshot): os.makedirs(args.snapshot) cudnn.benchmark = True train_loader = torch.utils.data.DataLoader(get_train_set(args), batch_size=args.batch_size, shuffle=True, num_workers=args.workers, pin_memory=True) gen = GenNet().cuda() disc = DisNet().cuda()
', 100ms<t<1s: ' + str(mysql_stat["ttl100ms1s"]) + \ ', 1s<t<10s: ' + str(mysql_stat["ttl1s10s"]) + \ ', 10s<t: ' + str(mysql_stat["ttlmore10s"]) + "\n" i += 1 request.add_output_header('Connection', 'close') request.add_output_header('Content-type', 'text/plain') request.add_output_header('Content-length', str(len(msg))) request.send_reply(200, 'OK', msg) pass def process_stats(): print "This is a stats processing thread" while True: time.sleep(60) print "Let's process stats" setproctitle("yybal") mysql_stats = [] # The connection state should not be defined globally, it should be isolated at a connection level # to prevent situations when a server becomes alive for not properly initialized conns # We use this global state for reporting only # Question: what to do with persistent connections? mysql_stats.append({"globalstate":"alive", "numqueries":0, "ttlless1ms":0, "ttl1ms10ms":0, "ttl10ms100ms":0, "ttl100ms1s":0, "ttl1s10s":0, "ttlmore10s":0}) mysql_stats.append({"globalstate":"alive", "numqueries":0, "ttlless1ms":0, "ttl1ms10ms":0, "ttl10ms100ms":0, "ttl100ms1s":0, "ttl1s10s":0, "ttlmore10s":0}) thread.start_new_thread(process_stats, ()) gevent.monkey.patch_socket() statsserver = HTTPServer(('', 9080), stathandler) statsserver.start() server = StreamServer(('127.0.0.1', 33306), handle) # creates a new server server.serve_forever() # start accepting new connections
# 4) back to step 1. (Define number of loops) # # TODO: - see TODOs thoughout code below ##################################################### #!/usr/bin/env python import os import subprocess import sys import time import threading import signal import logging from setproctitle import * setproctitle('master_test') # set process name for ROS to identify TIMEALLOWED = 10 # change to a large number(e.g. 5 minutes) for actual tests """ Clear all existing generated files""" """ TODO: implement the Initialize function once the AI code is made""" def Initialize(): #delete bag files os.chdir( '/home/f1/catkin_ws/src/racecar_simulator/racecar_gazebo/launch/test_runs/test_results' ) subprocess.call('rm *.bag', shell=True) """ runs roslaunch file to implement test run in gazebo and terminates once the robot reaches its goal"""