def clear_harakiri(_): if uwsgi: try: # Setting user harakiri to 0 means to clear pending timeout if any uwsgi.set_user_harakiri(0) except: # teardown_request must not fail app.logger.exception("Failed to clear user harakiri")
def apply_reverse_proxy_timeout(): timestamp = request.environ.get("GEN3_REQUEST_TIMESTAMP") timeout = request.environ.get("GEN3_TIMEOUT_SECONDS") if not timestamp or not timeout: return None timeout = float(timestamp) + float(timeout.rstrip("s")) - time.time() if timeout < 1: # We don't proceed if the time remaining is less than 1 second because the # minimal harakiri time is 1 second. Therefore it is important to set # GEN3_TIMEOUT_SECONDS larger than 1 second, not even close. app.logger.info( "Not enough time to handle the request; discarding now.") abort(504) if uwsgi: # GOTCHA: the int here is intentional over round, because we need a smaller # timeout than reverse proxy timeout = int(timeout) uwsgi.set_user_harakiri(timeout) app.logger.debug("Set user harakiri in %d seconds.", timeout)
def real_call(self, *args, **kwargs): uwsgi.set_user_harakiri(self.s) r = self.f(*args, **kwargs) uwsgi.set_user_harakiri(0) return r
def export_entities(program, project): """ Return a file with the requested entities as an attachment. Either ``ids`` or ``node_label`` must be provided in the parameters. When both are provided, ``node_label`` is ignored and ``ids`` is used. If ``ids`` is provided, all entities matching given ``ids`` will be exported. If there is only one entity type in the output, it will return a ``{node_type}.tsv`` or ``{node_type}.json`` file, e.g.: ``aliquot.tsv``. If there are multiple entity types, it returns ``gdc_export_{one_time_sha}.tar.gz`` for TSV format, or ``gdc_export_{one_time_sha}.json`` for JSON format. CSV is similar to TSV. If ``node_label`` is provided, it will export all entities of type with name ``node_label`` to a TSV file or JSON file. CSV is not supported yet in this case. Summary: Export entities Tags: export Args: program (str): |program_id| project (str): |project_id| Query Args: ids (str): one or a list of node IDs seperated by commas. node_label (str): type of nodes to look up, for example ``'case'`` format (str): output format, ``json`` or ``tsv`` or ``csv``; default is ``tsv`` with_children (str): whether to recursively find children or not; default is False category (str): category of node to filter on children. Example: ``clinical`` without_id (bool): whether to include the ids in the export file; default is False Responses: 200: Success 400: Bad Request 404: No id is found 403: Unauthorized request. """ try: import uwsgi except ImportError: # not in uWSGI, skip pass else: if hasattr(uwsgi, "set_user_harakiri"): # disable HARAKIRI because export is meant to take a long time uwsgi.set_user_harakiri(0) if flask.request.method == "GET": # Unpack multidict, or values will unnecessarily be lists. kwargs = {k: v for k, v in flask.request.args.items()} else: kwargs = utils.parse.parse_request_json() # Convert `format` argument to `file_format`. if "format" in kwargs: kwargs["file_format"] = kwargs["format"] del kwargs["format"] without_id = kwargs.get("without_id", "false").lower() == "true" node_label = kwargs.get("node_label") project_id = "{}-{}".format(program, project) file_format = kwargs.get("file_format") or "tsv" mimetype = ( "application/json" if file_format.lower() == "json" else "application/octet-stream" ) if not kwargs.get("ids"): if not node_label: raise UserError("expected either `ids` or `node_label` parameter") filename = "{}.{}".format(node_label, file_format) content_disp = "attachment; filename={}".format(filename) headers = {"Content-Disposition": content_disp} utils.transforms.graph_to_doc.validate_export_node(node_label) return flask.Response( flask.stream_with_context( utils.transforms.graph_to_doc.export_all( node_label, project_id, file_format, flask.current_app.db, without_id, ) ), mimetype=mimetype, headers=headers, ) else: output = utils.transforms.graph_to_doc.ExportFile( program=program, project=project, **kwargs ) content_disp = "attachment; filename={}".format(output.filename) headers = {"Content-Disposition": content_disp} return flask.Response( flask.stream_with_context(output.get_response()), mimetype=mimetype, headers=headers, )
""" uwsgi.chunked_read_nb() """ def uwsgi_pypy_chunked_read_nb(): wsgi_req = uwsgi_pypy_current_wsgi_req(); rlen = ffi.new("size_t*") chunk = lib.uwsgi_chunked_read(wsgi_req, rlen, 0, 1) if chunk == ffi.NULL: if lib.uwsgi_is_again() > 0: return None raise IOError("unable to receive chunked part") return ffi.string(chunk, rlen[0]) uwsgi.chunked_read_nb = uwsgi_pypy_chunked_read_nb """ uwsgi.set_user_harakiri(sec) """ uwsgi.set_user_harakiri = lambda x: lib.set_user_harakiri(x) print "Initialized PyPy with Python", sys.version print "PyPy Home:", sys.prefix """ Continulets support """ # this is the dictionary of continulets (one per-core) uwsgi_pypy_continulets = {}