def runIterations(simGear,
                  fightStyle,
                  profile,
                  metric,
                  statWeights,
                  enemies,
                  maxthreads,
                  iterations,
                  talentSets=None):
    manager = multiprocessing.Manager()

    gearQueue = manager.Queue(maxthreads * 2)
    tempResultsQueue = manager.Queue()
    resultsQueue = manager.Queue()
    progressQueue = manager.Queue()

    resultsList = []

    gearObj = gear.Gear(simGear)
    talentCount = len(talentSets) if talentSets else 1
    totalGearSets = gearObj.getPossibleCount() * talentCount

    progressProcess = multiprocessing.Process(target=printProgress,
                                              name="progress",
                                              args=(totalGearSets,
                                                    progressQueue, iterations))
    progressProcess.start()

    resultProcesserProcess = multiprocessing.Process(target=resultProcesser,
                                                     name="resultProcesser",
                                                     args=(tempResultsQueue,
                                                           resultsQueue,
                                                           metric))
    resultProcesserProcess.start()

    threads = 1 if isLastIteration(iterations) else maxthreads

    simProcesses = [
        multiprocessing.Process(target=worker,
                                args=(fightStyle, profile, metric, statWeights,
                                      enemies, maxthreads, iterations,
                                      gearQueue, tempResultsQueue,
                                      progressQueue)) for i in range(threads)
    ]
    gearProcess = multiprocessing.Process(target=gearObj.getGear,
                                          name="gearWorker",
                                          args=(gearQueue, talentSets))

    for proc in simProcesses:
        proc.start()
    gearProcess.start()

    gearProcess.join()

    for proc in simProcesses:
        gearQueue.put(None)
    for proc in simProcesses:
        proc.join()

    tempResultsQueue.put(None)
    resultProcesserProcess.join()

    progressQueue.put(None)
    progressProcess.join()

    print()

    while resultsQueue.qsize() != 0:
        result = resultsQueue.get()
        if result is not False:
            resultsList.append(result)

    return resultsList
Exemple #2
0
#@-others
################# (4) 程式啟動區
# 配合程式檔案所在目錄設定靜態目錄或靜態檔案
application_conf = {
    '/static': {
        'tools.staticdir.on': True,
        # 程式執行目錄下, 必須自行建立 static 目錄
        'tools.staticdir.dir': _curdir + "/static"
    },
    '/downloads': {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': data_dir + "/downloads"
    },
    '/images': {
        'tools.staticdir.on': True,
        'tools.staticdir.dir': data_dir + "/images"
    }
}
root = Hello()
root.gear = gear.Gear()
cherrypy.server.socket_port = 8088
cherrypy.server.socket_host = '127.0.0.1'
if 'OPENSHIFT_REPO_DIR' in os.environ.keys():
    # 表示在 OpenSfhit 執行
    application = cherrypy.Application(root, config=application_conf)
else:
    # 表示在近端執行
    cherrypy.quickstart(root, config=application_conf)
#@-leo
Exemple #3
0
"""
The simplest example of genearting a gear and exporting it in SVG and DXF formats.

The outputs are saved in the same dictory as "basic_gear.svg" and "basic_gear.dxf".

"""

import gear

# Create a gear
g = gear.Gear(48, 32, 20)

# Get the geometry
geom = g.get_geometry(bore=0.125)

# Save the DXF
geom.write_dxf('basic_gear.dxf')

# Save the SVG
# ------------

# SVG attributes
scale = 500
margin_factor = 0.2

# Draw using a black line
style = {'stroke': 'black', 'stroke-width': 0.002, 'fill': 'transparent'}

# Add the geometry to the SVG
geom.write_svg('basic_gear.svg', scale, style=style)