mirror of
https://github.com/clearml/clearml
synced 2025-02-07 13:23:40 +00:00
Optimize version update check
This commit is contained in:
parent
1f4c07bb56
commit
7beddf97da
@ -965,7 +965,7 @@ class StorageHelper(object):
|
||||
|
||||
class _HttpDriver(object):
|
||||
""" LibCloud http/https adapter (simple, enough for now) """
|
||||
timeout = (5.0, None)
|
||||
timeout = (5.0, 30.)
|
||||
|
||||
class _Container(object):
|
||||
def __init__(self, name, retries=5, **kwargs):
|
||||
|
@ -1,8 +1,9 @@
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
import collections
|
||||
import itertools
|
||||
import re
|
||||
import threading
|
||||
|
||||
import requests
|
||||
import six
|
||||
if six.PY3:
|
||||
@ -308,7 +309,12 @@ class CheckPackageUpdates(object):
|
||||
# noinspection PyBroadException
|
||||
try:
|
||||
cls._package_version_checked = True
|
||||
releases = requests.get('https://pypi.python.org/pypi/trains/json').json()['releases'].keys()
|
||||
# Sending the request only for statistics
|
||||
update_statistics = threading.Thread(target=CheckPackageUpdates.get_version_from_updates_server)
|
||||
update_statistics.daemon = True
|
||||
update_statistics.start()
|
||||
|
||||
releases = requests.get('https://pypi.python.org/pypi/trains/json', timeout=3.0).json()['releases'].keys()
|
||||
|
||||
releases = [Version(r) for r in releases]
|
||||
latest_version = sorted(releases)
|
||||
@ -323,3 +329,10 @@ class CheckPackageUpdates(object):
|
||||
return str(latest_version[-1]), not_patch_upgrade
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_version_from_updates_server():
|
||||
try:
|
||||
_ = requests.get('https://updates.trainsai.io/updates', timeout=1.0)
|
||||
except Exception:
|
||||
pass
|
||||
|
31
trains/utilities/io_manager.py
Normal file
31
trains/utilities/io_manager.py
Normal file
@ -0,0 +1,31 @@
|
||||
class IOCallsManager(object):
|
||||
|
||||
def __init__(self):
|
||||
self.threads_io = {}
|
||||
|
||||
def add_io_to_thread(self, thread_id, io_object):
|
||||
if thread_id in self.threads_io:
|
||||
self.threads_io[thread_id].add(id(io_object))
|
||||
else:
|
||||
self.threads_io[thread_id] = {id(io_object)}
|
||||
if self._io_has_canvas_figure(io_object):
|
||||
self.threads_io[thread_id].add(id(io_object.canvas.figure))
|
||||
|
||||
def is_plot_called(self, thread_id, io_object):
|
||||
return id(io_object) in self.threads_io.get(thread_id, set())
|
||||
|
||||
def remove_io_to_thread(self, thread_id, io_object):
|
||||
try:
|
||||
self.threads_io[thread_id].remove(id(io_object))
|
||||
if self._io_has_canvas_figure(io_object):
|
||||
self.threads_io[thread_id].remove(id(io_object.canvas.figure))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def remove_thread(self, thread_id):
|
||||
if thread_id in self.threads_io:
|
||||
del self.threads_io[thread_id]
|
||||
|
||||
@staticmethod
|
||||
def _io_has_canvas_figure(io_object):
|
||||
return hasattr(io_object, 'canvas') and hasattr(io_object.canvas, 'figure')
|
Loading…
Reference in New Issue
Block a user