diff --git a/trains/storage/helper.py b/trains/storage/helper.py index fb4b771a..6c745ba2 100644 --- a/trains/storage/helper.py +++ b/trains/storage/helper.py @@ -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): diff --git a/trains/utilities/check_updates.py b/trains/utilities/check_updates.py index 860d4075..b66b68db 100644 --- a/trains/utilities/check_updates.py +++ b/trains/utilities/check_updates.py @@ -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 diff --git a/trains/utilities/io_manager.py b/trains/utilities/io_manager.py new file mode 100644 index 00000000..433cee61 --- /dev/null +++ b/trains/utilities/io_manager.py @@ -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')