A simple reminder for myself of some often used commands. Plenty of useful docs over on https://git-annex.branchable.com/
This is a work in progress notebook...
| import re | |
| def parse_compact_range(expression): | |
| numbers = set() | |
| for match_ in re.finditer(r"(?:(\d+)\s*\-\s*(\d+)|(\d+))\s*(?:,|$)", expression): | |
| start, stop, exact = match_.group(1,2,3) | |
| if exact is not None: | |
| numbers.add(int(exact)) | |
| else: | |
| begin, end = sorted(map(int, (start, stop))) |
A simple reminder for myself of some often used commands. Plenty of useful docs over on https://git-annex.branchable.com/
This is a work in progress notebook...
| import re | |
| import os | |
| import html | |
| import shutil | |
| import logging | |
| import tempfile | |
| from functools import partial | |
| from threading import Lock | |
| from urllib.request import urlopen, Request |
| from multiprocessing import Pool as MPool, current_process | |
| from gevent.threadpool import ThreadPool | |
| from gevent.pool import Pool as GPool | |
| from contextlib import closing | |
| class ProcessPool(ThreadPool): | |
| def __init__(self, procs, **kwargs): | |
| super(ProcessPool, self).__init__(procs) | |
| self._m_pool = MPool(procs, **kwargs) |
| from PyQt5 import QtWidgets, QtCore | |
| import gevent | |
| import random | |
| import weakref | |
| def getData(key): | |
| data = "{}_{}_{}".format(key[0], key[1], random.choice("abcdefg")) | |
| gevent.sleep(random.random() * 5 + 2) | |
| return data |
| from PyQt5 import QtWidgets, QtCore | |
| import gevent | |
| def test(): | |
| print("PRESSED") | |
| for i in range(5): | |
| gevent.sleep(1) | |
| print("Waited", i) | |
| print("Done") |
| from __future__ import print_function | |
| import re | |
| import imp | |
| import sys | |
| import time | |
| import types | |
| import inspect | |
| import logging | |
| import threading |
| # Permission to use, copy, modify, and/or distribute this software for any purpose with or without | |
| # fee is hereby granted. | |
| # | |
| # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| # THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | |
| # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER | |
| # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE | |
| # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| # Example: |
| # Permission to use, copy, modify, and/or distribute this software for any purpose with or without | |
| # fee is hereby granted. | |
| # | |
| # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| # THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE | |
| # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER | |
| # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE | |
| # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| # Pickle iterator for multiprocessing.Manager |
| from __future__ import print_function | |
| from threading import Thread | |
| from pickle import dumps, loads | |
| from six.moves.queue import Empty | |
| from itertools import chain, count | |
| from multiprocessing.util import Finalize | |
| from concurrent.futures import Future, ProcessPoolExecutor |