| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent aa4d41b commit e9a8289
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -366,3 +366,20 @@ default an exception is raised for these errors. | |||
| 366 | 366 | ||
| 367 | 367 | gl = gitlab.gitlab(url, token, api_version=4) | |
| 368 | 368 | gl.projects.list(all=True, retry_transient_errors=True) | |
| 369 | + | ||
| 370 | + Timeout | ||
| 371 | + ------- | ||
| 372 | + | ||
| 373 | + python-gitlab will by default use the ``timeout`` option from it's configuration | ||
| 374 | + for all requests. This is passed downwards to the ``requests`` module at the | ||
| 375 | + time of making the HTTP request. However if you would like to override the | ||
| 376 | + global timeout parameter for a particular call, you can provide the ``timeout`` | ||
| 377 | + parameter to that API invocation: | ||
| 378 | + | ||
| 379 | + .. code-block:: python | ||
| 380 | + | ||
| 381 | + import gitlab | ||
| 382 | + | ||
| 383 | + gl = gitlab.gitlab(url, token, api_version=4) | ||
| 384 | + gl.projects.import_github(ACCESS_TOKEN, 123456, "root", timeout=120.0) | ||
| 385 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -491,6 +491,8 @@ def http_request( | |||
| 491 | 491 | ||
| 492 | 492 | verify = opts.pop("verify") | |
| 493 | 493 | timeout = opts.pop("timeout") | |
| 494 | + # If timeout was passed into kwargs, allow it to override the default | ||
| 495 | + timeout = kwargs.get("timeout", timeout) | ||
| 494 | 496 | ||
| 495 | 497 | # We need to deal with json vs. data when uploading files | |
| 496 | 498 | if files: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4745,13 +4745,7 @@ def import_project( | |||
| 4745 | 4745 | ) | |
| 4746 | 4746 | ||
| 4747 | 4747 | def import_github( | |
| 4748 | - self, | ||
| 4749 | - personal_access_token, | ||
| 4750 | - repo_id, | ||
| 4751 | - target_namespace, | ||
| 4752 | - new_name=None, | ||
| 4753 | - timeout_override=60.0, | ||
| 4754 | - **kwargs | ||
| 4748 | + self, personal_access_token, repo_id, target_namespace, new_name=None, **kwargs | ||
| 4755 | 4749 | ): | |
| 4756 | 4750 | """Import a project from Github to Gitlab (schedule the import) | |
| 4757 | 4751 | ||
@@ -4761,15 +4755,14 @@ def import_github( | |||
| 4761 | 4755 | operation has completed. | |
| 4762 | 4756 | ||
| 4763 | 4757 | NOTE: this request may take longer than most other API requests. | |
| 4764 | - So this method will override the session timeout with <timeout_override>, | ||
| 4765 | - which defaults to 60 seconds. | ||
| 4758 | + So this method will specify a 60 second default timeout if none is specified. | ||
| 4759 | + A timeout can be specified via kwargs to override this functionality. | ||
| 4766 | 4760 | ||
| 4767 | 4761 | Args: | |
| 4768 | 4762 | personal_access_token (str): GitHub personal access token | |
| 4769 | 4763 | repo_id (int): Github repository ID | |
| 4770 | 4764 | target_namespace (str): Namespace to import repo into | |
| 4771 | 4765 | new_name (str): New repo name (Optional) | |
| 4772 | - timeout_override (int or float): Timeout to use for this request | ||
| 4773 | 4766 | **kwargs: Extra options to send to the server (e.g. sudo) | |
| 4774 | 4767 | ||
| 4775 | 4768 | Raises: | |
@@ -4801,10 +4794,17 @@ def import_github( | |||
| 4801 | 4794 | } | |
| 4802 | 4795 | if new_name: | |
| 4803 | 4796 | data["new_name"] = new_name | |
| 4804 | - prev_timeout = self.gitlab.timeout | ||
| 4805 | - self.gitlab.timeout = timeout_override | ||
| 4797 | + if ( | ||
| 4798 | + "timeout" not in kwargs | ||
| 4799 | + or self.gitlab.timeout is None | ||
| 4800 | + or self.gitlab.timeout < 60.0 | ||
| 4801 | + ): | ||
| 4802 | + # Ensure that this HTTP request has a longer-than-usual default timeout | ||
| 4803 | + # The base gitlab object tends to have a default that is <10 seconds, | ||
| 4804 | + # and this is too short for this API command, typically. | ||
| 4805 | + # On the order of 24 seconds has been measured on a typical gitlab instance. | ||
| 4806 | + kwargs["timeout"] = 60.0 | ||
| 4806 | 4807 | result = self.gitlab.http_post("/import/github", post_data=data, **kwargs) | |
| 4807 | - self.gitlab.timeout = prev_timeout | ||
| 4808 | 4808 | return result | |
| 4809 | 4809 | ||
| 4810 | 4810 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments