示例#1
0
    def list(self, request, *args, **kw):

        procname = "worker:(pid:{:d}) {}".format(os.getpid(),
                                                 self.request.path)
        uwsgi.setprocname(procname)

        # Do some work!
        time.sleep(30)

        # Work Done - Call myself idle
        uwsgi.setprocname("worker:(pid:{:d}) {}".format(os.getpid(), "idle"))

        return Response(dict(message="Ok"), 200)
示例#2
0
def set_uwsgi_proc_name():
    build_dir = os.path.basename(project_root)
    try:
        deploy_tag = open(os.path.join(project_root, '.DEPLOY_TAG')).read().strip()
    except IOError:
        deploy_tag = '?'

    os.environ['DEPLOY_TAG'] = deploy_tag

    uwsgi.setprocname("uwsgi worker %(worker_id)d <%(build)s> [%(tag)s]" % {
        'worker_id': uwsgi.worker_id(),
        'build': build_dir,
        'tag': deploy_tag,
    })
示例#3
0
文件: welcome.py 项目: wu-h/uwsgi
def application(env, start_response):
    try:
        uwsgi.mule_msg(env['REQUEST_URI'], 1)
    except:
        pass

    req = uwsgi.workers()[uwsgi.worker_id() - 1]['requests']

    uwsgi.setprocname("worker %d managed %d requests" %
                      (uwsgi.worker_id(), req))

    try:
        gc.collect(2)
    except:
        pass
    if DEBUG:
        print(env['wsgi.input'].fileno())

    if env['PATH_INFO'] in routes:
        return routes[env['PATH_INFO']](env, start_response)

    if DEBUG:
        print(env['wsgi.input'].fileno())

    try:
        gc.collect(2)
    except:
        pass

    if DEBUG:
        print(len(gc.get_objects()))

    workers = ''
    for w in uwsgi.workers():
        apps = '<table border="1"><tr><th>id</th><th>mountpoint</th><th>startup time</th><th>requests</th></tr>'
        for app in w['apps']:
            apps += '<tr><td>%d</td><td>%s</td><td>%d</td><td>%d</td></tr>' % (
                app['id'], app['mountpoint'], app['startup_time'],
                app['requests'])
        apps += '</table>'
        workers += """
<tr>
<td>%d</td><td>%d</td><td>%s</td><td>%d</td><td>%d</td><td>%d</td><td>%s</td>
</tr>
        """ % (w['id'], w['pid'], w['status'], w['running_time'] / 1000,
               w['avg_rt'] / 1000, w['tx'], apps)

    output = """
<img src="/logo"/> version %s running on %s (remote user: %s)<br/>
<hr size="1"/>

Configuration<br/>
<iframe src="/config"></iframe><br/>

<br/>
Workers and applications<br/>
<table border="1">
<tr>
<th>wid</th><th>pid</th><th>status</th><th>running time</th><th>average</th><th>tx</th><th>apps</th>
</tr>
%s
</table>

    """ % (uwsgi.version, uwsgi.hostname, env.get('REMOTE_USER',
                                                  'None'), workers)

    start_response('200 OK', [('Content-Type', 'text/html'),
                              ('Content-Length', str(len(output)))])

    # return bytes(output.encode('latin1'))
    return output
示例#4
0
文件: welcome.py 项目: wu-h/uwsgi
def setprocname():
    if uwsgi.worker_id() > 0:
        uwsgi.setprocname("i am the worker %d" % uwsgi.worker_id())
示例#5
0
def worker():
    mule_id = uwsgi.mule_id()
    if mule_id == 0:
        uwsgi.setprocname("%s worker %s" % (app_name, uwsgi.worker_id()))
    else:
        uwsgi.setprocname("%s mule %s" % (app_name, uwsgi.mule_id()))
示例#6
0
    elif 'cron_by_celery_worker' in config.options:
        print "Using UWSGI TIMER TO TRIGGER CRON IN CELERY WORKER!"
        uwsgi.register_signal(99, "mule1", celery_cron_trigger)
        uwsgi.add_rb_timer(99, period_sec)
    else:
        uwsgi.register_signal(99, "mule1", cron_works)
        uwsgi.add_rb_timer(99, period_sec)

    # else:
    #     uwsgi.register_signal(99, "mule1", cron_works)
    #     # uwsgi.register_signal(101,"mule2", notify_wechat_news)
    #     print 'Register Signal 99 for mule1 as Cron workers'

    # linux 2.6.25以下内核.不支持timerfd.所以使用rb_timer.

    # uwsgi.add_rb_timer(101,60)
    # uwsgi.register_signal(100, "workers", v7_reload)
    # uwsgi.register_signal(101, "workers", service_active)
    # uwsgi.register_signal(102, "workers", service_deactive)

    return application2


def bootstrap():
    v9_load_conf()
    v9_init()
    return v9_application()


uwsgi.setprocname("%s master" % app_name)
示例#7
0
def application(env, start_response):
    try:
        uwsgi.mule_msg(env['REQUEST_URI'], 1)
    except:
        pass

    req = uwsgi.workers()[uwsgi.worker_id()-1]['requests']

    uwsgi.setprocname("worker %d managed %d requests" % (uwsgi.worker_id(), req))

    try:
        gc.collect(2)
    except:
        pass
    if DEBUG:
        print(env['wsgi.input'].fileno())

    if env['PATH_INFO'] in routes:
        return routes[env['PATH_INFO']](env, start_response)


    if DEBUG:
        print(env['wsgi.input'].fileno())

    try:
        gc.collect(2)
    except:
        pass

    if DEBUG:
        print(len(gc.get_objects()))

    workers = ''
    for w in uwsgi.workers():
        apps = '<table border="1"><tr><th>id</th><th>mountpoint</th><th>startup time</th><th>requests</th></tr>'
        for app in w['apps']:
            apps += '<tr><td>%d</td><td>%s</td><td>%d</td><td>%d</td></tr>' % (app['id'], app['mountpoint'], app['startup_time'], app['requests']) 
        apps += '</table>'
        workers += """
<tr>
<td>%d</td><td>%d</td><td>%s</td><td>%d</td><td>%d</td><td>%d</td><td>%s</td>
</tr>
        """ % (w['id'], w['pid'], w['status'], w['running_time']/1000, w['avg_rt']/1000, w['tx'], apps)

    output = """
<img src="/logo"/> version %s running on %s (remote user: %s)<br/>
<hr size="1"/>

Configuration<br/>
<iframe src="/config"></iframe><br/>

<br/>

Dynamic options<br/>
<iframe src="/options"></iframe><br/>

<br/>
Workers and applications<br/>
<table border="1">
<tr>
<th>wid</th><th>pid</th><th>status</th><th>running time</th><th>average</th><th>tx</th><th>apps</th>
</tr>
%s
</table>

    """ % (uwsgi.version, uwsgi.hostname, env.get('REMOTE_USER','None'), workers)

    start_response('200 OK', [('Content-Type', 'text/html'), ('Content-Length', str(len(output)) )])

    #return bytes(output.encode('latin1'))
    return output
示例#8
0
def setprocname():
    if uwsgi.worker_id() > 0:
        uwsgi.setprocname("i am the worker %d" % uwsgi.worker_id())
示例#9
0
 def unset_process_name(sender, **kwargs):
     setprocname('uwsgi (idle)')
示例#10
0
 def set_process_name_for_request(sender, environ, **kwargs):
     path = environ.get('PATH_INFO', '<unknown>')
     setprocname('uwsgi ' + path)
示例#11
0
文件: welcome.py 项目: sashka/uwsgi
def application(env, start_response):

    try:
        uwsgi.mule_msg(env["REQUEST_URI"], 1)
    except:
        pass

    req = uwsgi.workers()[uwsgi.worker_id() - 1]["requests"]

    uwsgi.setprocname("worker %d managed %d requests" % (uwsgi.worker_id(), req))

    gc.collect(2)
    if DEBUG:
        print(env["wsgi.input"].fileno())

    if routes.has_key(env["PATH_INFO"]):
        return routes[env["PATH_INFO"]](env, start_response)

    start_response("200 OK", [("Content-Type", "text/html")])

    if DEBUG:
        print(env["wsgi.input"].fileno())

    gc.collect(2)

    if DEBUG:
        print(len(gc.get_objects()))

    workers = ""
    for w in uwsgi.workers():
        apps = '<table border="1"><tr><th>id</th><th>mountpoint</th><th>requests</th></tr>'
        for app in w["apps"]:
            apps += "<tr><td>%d</td><td>%s</td><td>%d</td></tr>" % (app["id"], app["mountpoint"], app["requests"])
        apps += "</table>"
        workers += """
<tr>
<td>%d</td><td>%d</td><td>%s</td><td>%d</td><td>%d</td><td>%d</td><td>%s</td>
</tr>
        """ % (
            w["id"],
            w["pid"],
            w["status"],
            w["running_time"] / 1000,
            w["avg_rt"] / 1000,
            w["tx"],
            apps,
        )

    return """
<img src="/logo"/> version %s<br/>
<hr size="1"/>

Configuration<br/>
<iframe src="/config"></iframe><br/>

<br/>

Dynamic options<br/>
<iframe src="/options"></iframe><br/>

<br/>
Workers and applications<br/>
<table border="1">
<tr>
<th>wid</th><th>pid</th><th>status</th><th>running time</th><th>average</th><th>tx</th><th>apps</th>
</tr>
%s
</table>

    """ % (
        uwsgi.version,
        workers,
    )
示例#12
0
 def __call__(self):
     if uwsgi.mule_id() == self.id:
         uwsgi.setprocname(self.name)
         self.function(self)
示例#13
0
def application(env, start_response):
    try:
        uwsgi.mule_msg(env["REQUEST_URI"], 1)
    except Exception:
        pass

    req = uwsgi.workers()[uwsgi.worker_id() - 1]["requests"]

    uwsgi.setprocname(b"worker %d managed %d requests" % (uwsgi.worker_id(), req))

    try:
        gc.collect(2)
    except Exception:
        pass
    if DEBUG:
        print(env["wsgi.input"].fileno())

    if env["PATH_INFO"] in routes:
        return routes[env["PATH_INFO"]](env, start_response)

    if DEBUG:
        print(env["wsgi.input"].fileno())

    try:
        gc.collect(2)
    except Exception:
        pass

    if DEBUG:
        print(len(gc.get_objects()))

    workers = ""
    for w in uwsgi.workers():
        apps = '<table border="1"><tr><th>id</th><th>mountpoint</th><th>startup time</th><th>requests</th></tr>'
        for app in w["apps"]:
            apps += "<tr><td>%d</td><td>%s</td><td>%d</td><td>%d</td></tr>" % (
                app["id"],
                app["mountpoint"],
                app["startup_time"],
                app["requests"],
            )
        apps += "</table>"
        workers += """
<tr>
<td>%d</td><td>%d</td><td>%s</td><td>%d</td><td>%d</td><td>%d</td><td>%s</td>
</tr>
        """ % (
            w["id"],
            w["pid"],
            w["status"],
            w["running_time"] / 1000,
            w["avg_rt"] / 1000,
            w["tx"],
            apps,
        )

    output = """
<img src="{script_name}/logo"/> version %s running on %s (remote user: %s)<br/>
<hr size="1"/>

Configuration<br/>
<iframe src="{script_name}/config"></iframe><br/>

<br/>
Workers and applications<br/>
<table border="1">
<tr>
<th>wid</th><th>pid</th><th>status</th><th>running time</th><th>average</th><th>tx</th><th>apps</th>
</tr>
%s
</table>

    """ % (
        uwsgi.version,
        uwsgi.hostname,
        env.get("REMOTE_USER", "None"),
        workers,
    )

    start_response(
        "200 OK", [("Content-Type", "text/html"), ("Content-Length", str(len(output)))]
    )

    return [output.format(script_name=env["SCRIPT_NAME"]).encode("utf-8")]