예제 #1
0
파일: environment.py 프로젝트: fabioz/coev
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='hewwolord', paths=paths)

    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = hewwolord.lib.helpers

    # Create the Genshi TemplateLoader
    config['pylons.app_globals'].genshi_loader = TemplateLoader(
        paths['templates'], auto_reload=True)

    # Setup the SQLAlchemy database engine
    if 'sqlalchemy.module' in config:
        config['sqlalchemy.module'] = __import__(config['sqlalchemy.module'])

    engine = engine_from_config(config, 'sqlalchemy.')
        
    try:
        import coev

        flagdict = {
            'coev.debug.lib.coev': coev.CDF_COEV,
            'coev.debug.lib.coev.dump': coev.CDF_COEV_DUMP,
            'coev.debug.lib.colock': coev.CDF_COLOCK,
            'coev.debug.lib.colock.dump': coev.CDF_COLOCK_DUMP,
            'coev.debug.lib.nbuf': coev.CDF_NBUF,
            'coev.debug.lib.nbuf.dump': coev.CDF_NBUF_DUMP,
            'coev.debug.lib.runq.dump': coev.CDF_RUNQ_DUMP,
            'coev.debug.lib.stack': coev.CDF_STACK,
            'coev.debug.lib.stack.dump': coev.CDF_STACK_DUMP }
        
        lib_debug_flags = 0
        for f in flagdict:
            if asbool(config.get(f, False)):
                lib_debug_flags |= flagdict[f]

        coev.setdebug(  asbool(config.get('coev.debug.module', False)),
                        lib_debug_flags )
                        
        import thread
        thread.stack_size(int(config.get('coev.stack.size', 2 * 1024 * 1024)))
    except ImportError:
        pass    
    
    mcservers = aslist(config['memcache.servers'])
    mcdebug = asbool(config['memcache.debug'])
    init_model(engine, mcservers, mcdebug)
예제 #2
0
파일: websetup.py 프로젝트: FrankNagel/qlc
def setup_app(command, conf, vars):
    """Place any commands to setup quanthistling here"""
    thread.stack_size(512 * 1024)
    
    # Don't reload the app if it was loaded under the testing environment
    if not pylons.test.pylonsapp:
        load_environment(conf.global_conf, conf.local_conf)

    # Create the tables if they don't already exist
    metadata.create_all(bind=Session.bind)
예제 #3
0
파일: thread_test.py 프로젝트: mdavid/dlr
def test_stack_size():
    import sys
    if is_cli or (sys.version_info[0] == 2 and sys.version_info[1] > 4) or sys.version_info[0] > 2:
        import thread
        
        size = thread.stack_size()
        Assert(size==0 or size>=32768)

        bad_size_list = [ 1, -1, -32768, -32769, -32767, -40000, 32767, 32766]
        for bad_size in bad_size_list:
            AssertError(ValueError, thread.stack_size, bad_size)
            
        good_size_list = [4096*10, 4096*100, 4096*1000, 4096*10000]
        for good_size in good_size_list:
            #CodePlex Work Item 7827
            if (is_cli or is_silverlight) and good_size<=50000: print "Ignoring", good_size, "for CLI"; continue
            temp = thread.stack_size(good_size)
            Assert(temp>=32768 or temp==0)
        
        def temp(): pass
        thread.start_new_thread(temp, ())
        temp = thread.stack_size(1024*1024)
        Assert(temp>=32768 or temp==0)
예제 #4
0
 def test_stack_size(self):
     import thread
     thread.stack_size(0)
     res = thread.stack_size(0)
     assert res == 0
     res = thread.stack_size(1024*1024)
     assert res == 0
     res = thread.stack_size(2*1024*1024)
     assert res == 1024*1024
     res = thread.stack_size(0)
     assert res == 2*1024*1024
예제 #5
0
def hashtag_stream(hashtags, auth):
    print "listening for %s" % ",".join(hashtags)
    twitter_stream = TwitterStream(auth=auth)
    try:
        iterator = twitter_stream.statuses.filter(track=",".join(hashtags))
    except:
        time.sleep(3)
        iterator = twitter_stream.statuses.filter(track=",".join(hashtags))
    while True:
        print "*"*40
        print "stack size: %d" % thread.stack_size()
        print "started thread worker for %s" % ",".join(hashtags)
        for tweet in iterator:
            try: 
                hashtag = "#"
                try:
                    for htag in hashtags:
                        if htag in str(tweet["text"]):
                            hashtag = str(htag)
                            err_count = bayespell.errors(tweet["text"])
                    
                    if hashtag.strip() != "#":
                        print hashtag, err_count
                        hashtag_object = Hashtag.objects.get(tag=hashtag)
                        hashtag_object.typos = hashtag_object.typos + err_count
                        hashtag_object.save()
                except:
                    pass
                continue
            except:
                time.sleep(3)
                twitter_stream = TwitterStream(auth=auth)
                try:
                    iterator = twitter_stream.statuses.filter(track=",".join(hashtags))
                except:
                    time.sleep(3)
                    iterator = twitter_stream.statuses.filter(track=",".join(hashtags))
                continue
예제 #6
0
filename = 'SCC.txt'
vert_number = 875714
max_scc_count = 5

def all():

	count = 0
	list_ = []
	with open(filename, 'r') as f:
		for line in f:
			node_list = line.split()
			edge = Edge(int(node_list[0]),int(node_list[1]))
			list_.append(edge)
			count += 1
			if count % 50000 == 0:
				logw("edges loaded from file:", count)

	compute_scc(list_)
	logw(list(reversed(max_scc)))

# need to overcome recursion depth limits in python
# other way - rewrite recursion to loop using own stack
sys.setrecursionlimit(100000)   
thread.stack_size(2**27)      #just big size
thread = threading.Thread( target = all )

start_time = time.clock()
thread.start()      
thread.join()
print time.clock() - start_time
예제 #7
0
import sys
import thread
sys.setrecursionlimit(10300)
thread.stack_size(1024 * 80)
n = input()
l = []
for i in range(n):
    l += [list(map(int, raw_input().split()))]
check = []


def isOK(x, y):
    global n
    if x < 0 or x >= n: return False
    if y < 0 or y >= n: return False
    return True


def dfs(x, y):
    global check, l, level

    if check[y][x] > 0: return
    check[y][x] = 1
    delta = [(1, 0), (0, 1), (0, -1), (-1, 0)]

    for a, b in delta:
        if isOK(a + x, b + y) and l[b + y][a + x] > level:
            dfs(a + x, b + y)

    return
예제 #8
0
import thread
thread.stack_size(512 * 1024)
예제 #9
0
                      dest="total",
                      type="int",
                      default=None,
                      help="total number of sessions to generate")
    parser.add_option("-d",
                      "--duration",
                      dest="duration",
                      type="int",
                      default=1,
                      help="total number of seconds to generate load")
    parser.add_option("-n",
                      "--seed",
                      dest="seed",
                      type="int",
                      default=100,
                      help="random number generator seed")

    (options, args) = parser.parse_args()

    # seed random number generator
    random.seed(options.seed)

    thread.stack_size(50000)

    # launch generator
    wg = WorkloadGenerator(options.host, options.port, options.load)
    if options.total:
        wg.startTotal(options.total)
    else:
        wg.startDuration(options.duration)
예제 #10
0
파일: scc.py 프로젝트: gitsubash/jt-classes
    #with open('SCCTest.txt', 'r') as f:
    #with open('SCCTest2.txt', 'r') as f:
        lines = f.readlines()
        x = 0
        for line in lines:
            if 0 == (x % 10000): print 'Read %d' % x
            edge = line.split()
            edge[0] = int(edge[0]) - 1
            edge[1] = int(edge[1]) - 1
            edges[edge[0]].append(edge[1])
            revEdges[edge[1]].append(edge[0])
            x += 1

    print 'Loaded'
    sys.setrecursionlimit(100000)
    thread.stack_size(2**27)
    t1 = threading.Thread(target = scc)
    begin = time.clock()
    t1.start()      # start the scc thread
    t1.join()       # and wait for it to finish
    print time.clock() - begin
    #scc()
    #print 'Done'
    l = []
    for scc in sccs: l.append(len(scc))
    l.sort()
    l.reverse()
    s = ''
    for i in xrange(5):
        if i >= len(l): s += '0,'
        else: s += str(l[i]) + ','
예제 #11
0
파일: main.py 프로젝트: crisisking/skybot
import re
import thread
import traceback

thread.stack_size(1024 * 512)  # reduce vm size


class Input(dict):

    def __init__(self, conn, raw, prefix, command, params,
                 nick, user, host, paraml, msg):

        server = conn.server_host

        chan = paraml[0].lower()
        if chan == conn.nick.lower():  # is a PM
            chan = nick

        def say(msg):
            conn.msg(chan, msg)

        def reply(msg):
            if chan == nick:  # PMs don't need prefixes
                self.say(msg)
            else:
                self.say(nick + ': ' + msg)

        def pm(msg, nick=nick):
            conn.msg(nick, msg)

        def set_nick(nick):
예제 #12
0
if __name__ == "__main__":
    gc.set_debug(gc.DEBUG_LEAK)
    parser = optparse.OptionParser(usage="%prog -h [host] -p [port] -l [load (sessions/s)] -d [duration (seconds)] -t [total (sessions)] -n [seed]", version="%prog 1.0")
    parser.add_option("-s", "--server", dest="host", type="str", default="localhost",
                      help= "server to connect to")
    parser.add_option("-p", "--port", dest="port", type="int", default=80,
                      help= "port number to connect to")
    parser.add_option("-l", "--load", dest="load", type="int", default=1,
                      help= "number of sessions to create per second")
    parser.add_option("-t", "--total", dest="total", type="int", default=None,
                      help= "total number of sessions to generate")
    parser.add_option("-d", "--duration", dest="duration", type="int", default=1,
                      help= "total number of seconds to generate load")
    parser.add_option("-n", "--seed", dest="seed", type="int", default=100,
                      help= "random number generator seed")
    
    (options, args) = parser.parse_args()

    # seed random number generator
    random.seed(options.seed)

    thread.stack_size(50000)

    # launch generator
    wg = WorkloadGenerator(options.host, options.port, options.load)
    if options.total:
        wg.startTotal(options.total)
    else:
        wg.startDuration(options.duration)

예제 #13
0
def thread_stack_size(size=None):
    if size is not None:
        raise thread.ThreadError()
    # doesn't really apply, but whatever
    return thread.stack_size()
예제 #14
0
import thread
import traceback

thread.stack_size(1024 * 512)  # reduce vm size


class Input(dict):
    def __init__(self, conn, raw, prefix, command, params, nick, user, host,
                 paraml, msg):

        chan = paraml[0].lower()
        if chan == conn.nick.lower():  # is a PM
            chan = nick

        def say(msg):
            conn.msg(chan, msg)

        def reply(msg):
            if chan == nick:  # PMs don't need prefixes
                conn.msg(chan, msg)
            else:
                conn.msg(chan, nick + ': ' + msg)

        def pm(msg):
            conn.msg(nick, msg)

        def set_nick(nick):
            conn.set_nick(nick)

        def me(msg):
            conn.msg(chan, "\x01%s %s\x01" % ("ACTION", msg))
    print 'finding top five largest SCCs...'
    dfs_loop_1st(g)
    dfs_loop_2nd(g)
    # filler is just to make the sort function works
    # because g.vertices[0] is not used
    filler = Vertex()
    g.vertices[0] = filler
    top_scc_s = sorted(g.vertices,
                       key=lambda vertex: vertex.minions,
                       reverse=True)
    for i in range(5):
        v = top_scc_s[i]
        print 'label:{0} t:{1} minions:{2}'.format(v.label, v.fscore,
                                                   v.minions)


# with the recursive way, two parameters need to be adjusted:
# (because the DFS recursive method can go really deep here)
# the default python recursive limit is 1000, which is not enough for the hw problem set
# the default thread stack size is 1mb? which is also not enough for the hw problem set
# (got the following code from the course's forum)
import sys, thread, threading, time
sys.setrecursionlimit(100000)
thread.stack_size(2**27)
t1 = threading.Thread(target=kosaraju, args=())

begin = time.clock()
t1.start()  # start the scc thread
t1.join()  # and wait for it to finish
print time.clock() - begin
예제 #16
0
def thread_stack_size(size=None):
    if size is not None:
        raise thread.ThreadError()
    # doesn't really apply, but whatever
    return thread.stack_size()
예제 #17
0
import sys
import random
import time
from Tkinter import *
import ImageTk
from threading import Thread
import thread
thread.stack_size(2**17) # allow some more threads

RADIUS=2
WIDTH, HEIGHT = 400, 400
FPS=40
COLOR_GREEN  = "#00FF00"
COLOR_GRAY   = "#DDDDDD"
COLOR_YELLOW = "#FAFAC8"

class Timer(Thread):
    "executes a task repeatedly "

    def __init__(self, update=None, wait_time=1.0):
        Thread.__init__(self)
        self.wait_time = wait_time # in secs as float
        self.update = update
        self.running = True

    def run(self):
        while self.running:
            time.sleep(self.wait_time)
            if self.running:
                self.update()
    global edgeOut

    explored[startVertex] = True
    leader[startVertex] = s
    leaders[s].append(startVertex)
    for edgeOut in edgesOut[startVertex]:
        if not explored[edgeOut]:
            DFS(edgeOut)


import sys, thread, threading, time
from math import *

sys.setrecursionlimit(100000)  # don't know what I actually needed here
thread.stack_size(
    2**27
)  # largest power of 2 that didn't give me an error, don't know what I needed
begin = time.clock()

print "opening file..."
filehandle = open("2sat6.txt")
lines = filehandle.readlines()
maxN = int(lines[0])
lines = lines[1:]
filehandle.close()
edges = [0] * (2 * len(lines))

for i in range(len(lines)):
    line = lines[i]
    #    if(i%1000==0):
    #        print ".",
예제 #19
0
    def run(self):
        # If we can, replace lgTaskProcessor with lgTaskSlave in our title
        try:
            import setproctitle
            title = setproctitle.getproctitle()
            if 'lgTaskProcessor' in title:
                title = title.replace('lgTaskProcessor', 'lgTaskSlave')
            else:
                title += ' --slave'
            setproctitle.setproctitle(title)
        except ImportError:
            pass
        # We're in our own process now, so disconnect the processor's 
        # pymongo connection to make sure we don't hold those sockets open
        self._processor.taskConnection.close()

        # Also, ensure that the global talk variables weren't copied over.
        # This only affects testing situations - that is, the normal processor
        # process won't use talk.
        import lgTask.talk
        lgTask.talk.talkConnection.resetFork()
        
        canQsize = True
        try:
            self._queue.qsize()
        except NotImplementedError:
            # Oh Mac OS X, how silly you are sometimes
            canQsize = False

        self._fixSigTerm()

        # rconsole?
        if self._processor._useRConsole:
            import lgTask.lib.rfooUtil as rfooUtil
            rfooUtil.spawnServer()

        # Any tasks that we start only really need a teeny bit of stack
        thread.stack_size(1024 * 1024)
        try:
            while True:
                try:
                    # See if we should be marked as accepting new tasks from
                    # the Processor
                    if self._isAccepting.value:
                        self._checkAccepting()

                    # Check tasks are running
                    self._checkRunning()

                    # Get new task
                    taskData = self._queue.get(
                        timeout = self._processor.KILL_INTERVAL
                    )
                    taskThread = InterruptableThread(
                        target = self._runTaskThreadMain
                        , args = (taskData,)
                    )
                    # Remember the ID so that we can check for "kill" states
                    taskThread.taskId = taskData['_id']
                    taskThread.start()
                    self._running.append(taskThread)
                    
                    # Update running count
                    newCount = len(self._running)
                    if canQsize:
                        newCount += self._queue.qsize()
                    self._runningCount.value = newCount

                except Empty:
                    pass
                except Exception:
                    self._processor.log("Slave error {0}: {1}".format(
                        self.pid, traceback.format_exc()
                    ))

                # After each iteration, see if we're alive
                if not self._shouldContinue():
                    break
        except:
            self._processor.log("Slave error {0}: {1}".format(
                self.pid, traceback.format_exc()
            ))
        finally:
            pass
예제 #20
0
import gc
import sys

from threading import Timer
import thread

thread.stack_size(1024 * 1024)  # 1Mb, default is 8Mb

# Setup hourly garbage collection (and stats printing)


def _gc_collect():
    # shows all the memleak info and stores
    # uncollectable objects to gc.garbage
    # sys.stderr.write("\n-- DUMP BEGIN --\n")
    # gc.set_debug(gc.DEBUG_LEAK)
    gc.collect()
    # sys.stderr.write("Uncollectable unreachable objects (sorry):\n")
    # for obj in gc.garbage:
    #    try:
    #        sys.stderr.write("%s\n" % (obj,))
    #    except:
    #        pass
    # sys.stderr.write("Quantity: %s\n" % (len(gc.garbage),))
    # sys.stderr.write("\n-- DUMP END --\n")
    # gc.set_debug(False)
    # now empty the list
    # del gc.garbage[:]
    # gc.collect()
    _setup_timer()
예제 #21
0
parser.add_argument('--socket', nargs='?', metavar='PATH',
                    help='path of the local socket')
parser.add_argument('--logfile', nargs='?', metavar='PATH',
                    help='path of the log file')
args = parser.parse_args()

# stderr doesn't work with FastCGI; the following is a hack to get a
# log file with diagnostics anyway
if args.logfile:
    sys.stderr = sys.stdout = file(args.logfile, 'a')

prev_sys_path = list(sys.path)

new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path

sys.path.append(os.path.dirname(sys.argv[0]))

thread.stack_size(524288)

wsgi_app = loadapp('config:' + os.path.abspath(args.config_file))
logging.config.fileConfig(args.config_file)

if __name__ == '__main__':
    WSGIServer(wsgi_app, bindAddress=args.socket, umask=0,
               minSpare=1, maxSpare=5, maxThreads=50).run()
예제 #22
0
    sccCountList.sort(reverse=True)
    print sccCountList[:5]


if __name__ == "__main__":
    sys.setrecursionlimit(200000)
    nodelist = []
    F = [Node()]
    count = 0
    leader = None
    for i in xrange(875715):
        nodelist.append(Node())

    read = open("SCC.txt", 'rb')
    line = read.readline()
    while line:
        nodes = line.split()
        if len(nodes) == 0:
            line = read.readline()
            continue
        firstIdx = int(nodes[0])
        secondIdx = int(nodes[1])
        if firstIdx != secondIdx:
            nodelist[firstIdx].To.append(secondIdx)
            nodelist[secondIdx].From.append(firstIdx)
        line = read.readline()
    read.close()

    thread.stack_size(1048576 * 128)
    thread.start_new_thread(ThreadGraph, (nodelist, ))
예제 #23
0
파일: Main.py 프로젝트: stuartw/WMCore
  def setup_server(self):
    """Configure CherryPy server from application configuration.

    Traverses the server configuration portion and applies parameters
    known to be for CherryPy to the CherryPy server configuration.
    These are: engine, hooks, log, request, respose, server, tools,
    wsgi, checker.

    Also applies pseudo-parameters ``thread_stack_size`` (default: 128kB)
    and ``sys_check_interval`` (default: 10000). The former sets the
    default stack size to desired value, to avoid excessively large
    thread stacks -- typical operating system default is 8 MB, which
    adds up rather a lot for lots of server threads. The latter sets
    python's ``sys.setcheckinterval``; the default is to increase this
    to avoid unnecessarily frequent checks for python's GIL, global
    interpreter lock. In general we want each thread to complete as
    quickly as possible without making unnecessary checks."""
    cpconfig = cherrypy.config

    # Determine server local base.
    port = getattr(self.srvconfig, 'port', 8080)
    local_base = getattr(self.srvconfig, 'local_base', socket.gethostname())
    if local_base.find(':') == -1:
      local_base = '%s:%d' % (local_base, port)

    # Set default server configuration.
    cherrypy.log = Logger()
    cpconfig.update({'server.max_request_body_size': 0})
    cpconfig.update({'server.environment': 'production'})
    cpconfig.update({'server.socket_host': '0.0.0.0'})
    cpconfig.update({'server.socket_port': port})
    cpconfig.update({'server.socket_queue_size': 100})
    cpconfig.update({'server.thread_pool': 100})
    cpconfig.update({'tools.proxy.on': True})
    cpconfig.update({'tools.proxy.base': local_base})
    cpconfig.update({'tools.time.on': True})
    cpconfig.update({'engine.autoreload_on': False})
    cpconfig.update({'request.show_tracebacks': False})
    cpconfig.update({'request.methods_with_bodies': ("POST", "PUT", "DELETE")})
    thread.stack_size(getattr(self.srvconfig, 'thread_stack_size', 128*1024))
    sys.setcheckinterval(getattr(self.srvconfig, 'sys_check_interval', 10000))
    self.silent = getattr(self.srvconfig, 'silent', False)

    # Apply any override options from app config file.
    for section in ('engine', 'hooks', 'log', 'request', 'response',
                    'server', 'tools', 'wsgi', 'checker'):
      if not hasattr(self.srvconfig, section):
        continue
      for opt, value in getattr(self.srvconfig, section).dictionary_().iteritems():
        if isinstance(value, ConfigSection):
          for xopt, xvalue in value.dictionary_().iteritems():
            cpconfig.update({"%s.%s.%s" % (section, opt, xopt): xvalue})
        elif isinstance(value, str) or isinstance(value, int):
          cpconfig.update({"%s.%s" % (section, opt): value})
        else:
          raise RuntimeError("%s.%s should be string or int, got %s"
                             % (section, opt, type(value)))

    # Apply security customisation.
    if hasattr(self.srvconfig, 'authz_defaults'):
      defsec = self.srvconfig.authz_defaults
      cpconfig.update({'tools.cms_auth.on': True})
      cpconfig.update({'tools.cms_auth.role': defsec['role']})
      cpconfig.update({'tools.cms_auth.group': defsec['group']})
      cpconfig.update({'tools.cms_auth.site': defsec['site']})

    if hasattr(self.srvconfig, 'authz_policy'):
      cpconfig.update({'tools.cms_auth.policy': self.srvconfig.authz_policy})
예제 #24
0
파일: Main.py 프로젝트: rishiloyola/WMCore
    def setup_server(self):
        """Configure CherryPy server from application configuration.

        Traverses the server configuration portion and applies parameters
        known to be for CherryPy to the CherryPy server configuration.
        These are: engine, hooks, log, request, respose, server, tools,
        wsgi, checker.

        Also applies pseudo-parameters ``thread_stack_size`` (default: 128kB)
        and ``sys_check_interval`` (default: 10000). The former sets the
        default stack size to desired value, to avoid excessively large
        thread stacks -- typical operating system default is 8 MB, which
        adds up rather a lot for lots of server threads. The latter sets
        python's ``sys.setcheckinterval``; the default is to increase this
        to avoid unnecessarily frequent checks for python's GIL, global
        interpreter lock. In general we want each thread to complete as
        quickly as possible without making unnecessary checks."""
        cpconfig = cherrypy.config

        # Determine server local base.
        port = getattr(self.srvconfig, 'port', 8080)
        local_base = getattr(self.srvconfig, 'local_base',
                             socket.gethostname())
        if local_base.find(':') == -1:
            local_base = '%s:%d' % (local_base, port)

        # Set default server configuration.
        cherrypy.log = Logger()
        cpconfig.update({'server.max_request_body_size': 0})
        cpconfig.update({'server.environment': 'production'})
        cpconfig.update({'server.socket_host': '0.0.0.0'})
        cpconfig.update({'server.socket_port': port})
        cpconfig.update({'server.socket_queue_size': 100})
        cpconfig.update({'server.thread_pool': 100})
        cpconfig.update({'tools.proxy.on': True})
        cpconfig.update({'tools.proxy.base': local_base})
        cpconfig.update({'tools.time.on': True})
        cpconfig.update({'engine.autoreload.on': False})
        cpconfig.update({'request.show_tracebacks': False})
        cpconfig.update(
            {'request.methods_with_bodies': ("POST", "PUT", "DELETE")})
        thread.stack_size(
            getattr(self.srvconfig, 'thread_stack_size', 128 * 1024))
        sys.setcheckinterval(
            getattr(self.srvconfig, 'sys_check_interval', 10000))
        self.silent = getattr(self.srvconfig, 'silent', False)

        # Apply any override options from app config file.
        for section in ('engine', 'hooks', 'log', 'request', 'response',
                        'server', 'tools', 'wsgi', 'checker'):
            if not hasattr(self.srvconfig, section):
                continue
            for opt, value in getattr(self.srvconfig,
                                      section).dictionary_().iteritems():
                if isinstance(value, ConfigSection):
                    for xopt, xvalue in value.dictionary_().iteritems():
                        cpconfig.update(
                            {"%s.%s.%s" % (section, opt, xopt): xvalue})
                elif isinstance(value, str) or isinstance(value, int):
                    cpconfig.update({"%s.%s" % (section, opt): value})
                else:
                    raise RuntimeError(
                        "%s.%s should be string or int, got %s" %
                        (section, opt, type(value)))

        # Apply security customisation.
        if hasattr(self.srvconfig, 'authz_defaults'):
            defsec = self.srvconfig.authz_defaults
            cpconfig.update({'tools.cms_auth.on': True})
            cpconfig.update({'tools.cms_auth.role': defsec['role']})
            cpconfig.update({'tools.cms_auth.group': defsec['group']})
            cpconfig.update({'tools.cms_auth.site': defsec['site']})

        if hasattr(self.srvconfig, 'authz_policy'):
            cpconfig.update(
                {'tools.cms_auth.policy': self.srvconfig.authz_policy})
        done.release()

print ('\n*** Barrier Test ***')
if done.acquire(0):
    raise ValueError("'done' should have remained acquired")
bar = barrier(numtasks)
running = numtasks
for i in range(numtasks):
    thread.start_new_thread(task2, (i,))
done.acquire()
print ('all tasks done')

if hasattr(thread, 'stack_size'):
    # not all platforms support changing thread stack size
    print ('\n*** Changing thread stack size ***')
    if thread.stack_size() != 0:
        raise ValueError("initial stack_size not 0")

    thread.stack_size(0)
    if thread.stack_size() != 0:
        raise ValueError("stack_size not reset to default")

    from os import name as os_name
    if os_name in ("nt", "os2", "posix"):

        tss_supported = 1
        try:
            thread.stack_size(4096)
        except ValueError:
            print ('caught expected ValueError setting stack_size(4096)')
        except thread.error:
예제 #26
0
파일: main.py 프로젝트: stoneLeaf/aimable
import thread
import traceback


thread.stack_size(1024 * 512)  # Reduce VM size


class Input(dict):
    def __init__(self, conn, raw, prefix, command, params,
                 nick, user, host, paraml, msg):

        chan = paraml[0].lower()
        if chan == conn.nick.lower():  # Is a PM
            chan = nick

        def say(msg):
            conn.msg(chan, msg)

        def reply(msg):
            if chan == nick:  # PMs don't need prefixes
                conn.msg(chan, msg)
            else:
                conn.msg(chan, nick + ': ' + msg)

        def pm(msg):
            conn.msg(nick, msg)

        def set_nick(nick):
            conn.set_nick(nick)

        def me(msg):
예제 #27
0
import thread
thread.stack_size(128*1024)

import socket
import re
import WMCore.HTTPFrontEnd.RequestManager.ReqMgrConfiguration as ReqMgrConfig
__all__ = []
from WMCore.WMInit import getWMBASE
import os.path
INSTALL = getWMBASE()

HOST = socket.getfqdn().lower()
COUCH = "https://%s/couchdb" % HOST
ADD_MONITOR_FLAG = False

if re.match(r"^vocms0(?:13[689]|140|16[135]|30[67]|318)\.cern\.ch$", HOST):
  COUCH = "https://cmsweb.cern.ch/couchdb"
elif re.match(r"^vocms0(?:13[12])\.cern\.ch$", HOST):
  COUCH = "https://cmsweb-testbed.cern.ch/couchdb"
elif re.match(r"^vocms0127\.cern\.ch$", HOST):
  COUCH = "https://cmsweb-dev.cern.ch/couchdb"

config = ReqMgrConfig.reqMgrConfig(installation=INSTALL,
  couchurl = COUCH, addMonitor = ADD_MONITOR_FLAG)

TEMPLATES = os.path.normpath(os.path.join(INSTALL, '../../../data/templates/WMCore/WebTools'))
JAVASCRIPT_PATH = os.path.normpath(os.path.join(INSTALL, '../../../data/javascript'))
HTML_PATH = os.path.normpath(os.path.join(INSTALL, '../../../data/html'))

config.webapp_("reqmgr")
config.reqmgr.html = os.path.join(HTML_PATH, 'RequestManager')
예제 #28
0
        done.release()


print '\n*** Barrier Test ***'
if done.acquire(0):
    raise ValueError, "'done' should have remained acquired"
bar = barrier(numtasks)
running = numtasks
for i in range(numtasks):
    thread.start_new_thread(task2, (i, ))
done.acquire()
print 'all tasks done'

# not all platforms support changing thread stack size
print '\n*** Changing thread stack size ***'
if thread.stack_size() != 0:
    raise ValueError, "initial stack_size not 0"

thread.stack_size(0)
if thread.stack_size() != 0:
    raise ValueError, "stack_size not reset to default"

from os import name as os_name
if os_name in ("nt", "os2", "posix"):

    tss_supported = 1
    try:
        thread.stack_size(4096)
    except ValueError:
        print 'caught expected ValueError setting stack_size(4096)'
    except thread.error:
예제 #29
0
    
    explored[startVertex]=True
    leader[startVertex]=s
    leaders[s].append(startVertex)
    for edgeOut in edgesOut[startVertex]:
        if not explored[edgeOut]:
            DFS(edgeOut)


import sys, thread, threading, time
from math import*



sys.setrecursionlimit(100000)   # don't know what I actually needed here
thread.stack_size(2**27)      # largest power of 2 that didn't give me an error, don't know what I needed
begin = time.clock()

print "opening file..."
filehandle=open("2sat6.txt")
lines=filehandle.readlines()
maxN=int(lines[0])
lines=lines[1:]
filehandle.close()   
edges=[0]*(2*len(lines))


for i in range(len(lines)):
        line=lines[i]
    #    if(i%1000==0):
    #        print ".",
예제 #30
0
    def test_stack_size(self):
        # Various stack size tests.
        self.assertEquals(thread.stack_size(), 0, "intial stack size is not 0")

        thread.stack_size(0)
        self.assertEquals(thread.stack_size(), 0,
                          "stack_size not reset to default")

        if os.name not in ("nt", "os2", "posix"):
            return

        tss_supported = True
        try:
            thread.stack_size(4096)
        except ValueError:
            verbose_print("caught expected ValueError setting "
                          "stack_size(4096)")
        except thread.error:
            tss_supported = False
            verbose_print("platform does not support changing thread stack "
                          "size")

        if tss_supported:
            fail_msg = "stack_size(%d) failed - should succeed"
            for tss in (262144, 0x100000, 0):
                thread.stack_size(tss)
                self.assertEquals(thread.stack_size(), tss, fail_msg % tss)
                verbose_print("successfully set stack_size(%d)" % tss)

            for tss in (262144, 0x100000):
                verbose_print("trying stack_size = (%d)" % tss)
                self.next_ident = 0
                self.created = 0
                for i in range(NUMTASKS):
                    self.newtask()

                verbose_print("waiting for all tasks to complete")
                self.done_mutex.acquire()
                verbose_print("all tasks done")

            thread.stack_size(0)
예제 #31
0
#from devices.device_base import DeviceBase
from devices.xbee.xbee_devices.xbee_base import XBeeBase
from devices.xbee.xbee_devices.xbee_serial import XBeeSerial
from settings.settings_base import SettingsBase, Setting
from channels.channel_source_device_property import *

from common.types.boolean import Boolean, STYLE_ONOFF
from devices.xbee.xbee_config_blocks.xbee_config_block_ddo \
    import XBeeConfigBlockDDO
from devices.xbee.xbee_device_manager.xbee_device_manager_event_specs \
    import *
from devices.xbee.common.addressing import *
from devices.xbee.common.prodid import RCS_THERMOSTAT
import time
import thread
thread.stack_size(2048*1024)



# classes
class XBeeSerialTerminal(XBeeSerial):
    """\
        This class extends one of our base classes and is intended as an
        example of a concrete, example implementation, but it is not itself
        meant to be included as part of our developer API. Please consult the
        base class documentation for the API and the source code for this file
        for an example implementation.

    """
    ADDRESS_TABLE = [ [0xe8, 0xc105, 0x11] ]
    
예제 #32
0
파일: cli.py 프로젝트: yskeem/nnabla
                               help='shuffle mode (true or false)',
                               required=True)
        subparser.add_argument('-f1',
                               '--file1',
                               help='output file name 1',
                               required=True)
        subparser.add_argument('-r1',
                               '--ratio1',
                               help='output file ratio(%) 1')
        subparser.add_argument('-f2', '--file2', help='output file name 2')
        subparser.add_argument('-r2',
                               '--ratio2',
                               help='output file ratio(%) 2')
        subparser.set_defaults(
            func=create_image_classification_dataset_command)
    except:
        pass

    args = parser.parse_args()
    args.func(args)


if __name__ == '__main__':
    import thread
    import threading
    thread.stack_size(128 * 1024 * 1024)
    sys.setrecursionlimit(0x3fffffff)
    main_thread = threading.Thread(target=main)
    main_thread.start()
    main_thread.join()
예제 #33
0
    def test_stack_size(self):
        # Various stack size tests.
        self.assertEquals(thread.stack_size(), 0, "intial stack size is not 0")

        thread.stack_size(0)
        self.assertEquals(thread.stack_size(), 0, "stack_size not reset to default")

        if os.name not in ("nt", "os2", "posix"):
            return

        tss_supported = True
        try:
            thread.stack_size(4096)
        except ValueError:
            verbose_print("caught expected ValueError setting "
                            "stack_size(4096)")
        except thread.error:
            tss_supported = False
            verbose_print("platform does not support changing thread stack "
                            "size")

        if tss_supported:
            fail_msg = "stack_size(%d) failed - should succeed"
            for tss in (262144, 0x100000, 0):
                thread.stack_size(tss)
                self.assertEquals(thread.stack_size(), tss, fail_msg % tss)
                verbose_print("successfully set stack_size(%d)" % tss)

            for tss in (262144, 0x100000):
                verbose_print("trying stack_size = (%d)" % tss)
                self.next_ident = 0
                self.created = 0
                for i in range(NUMTASKS):
                    self.newtask()

                verbose_print("waiting for all tasks to complete")
                self.done_mutex.acquire()
                verbose_print("all tasks done")

            thread.stack_size(0)
예제 #34
0
from src import systasks
from src import widgets

from src.config import config

if config['local-access-only']:
    bindto = '127.0.0.1'
else:
    bindto = '0.0.0.0'

cherrypy.process.servers.check_port(bindto, config['http-port'], timeout=1.0)
cherrypy.process.servers.check_port(bindto, config['https-port'], timeout=1.0)


MyExternalIPAdress = util.updateIP()
thread.stack_size(256000)

if config['change-process-title']:
    try:
        import setproctitle
        setproctitle.setproctitle("kaithem")
    except:
        pass

if config['enable-websockets']:
    from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
    from ws4py.websocket import EchoWebSocket
    WebSocketPlugin(cherrypy.engine).subscribe()
    cherrypy.tools.websocket = WebSocketTool()