Exemplo n.º 1
0
    def Init():
        """Setup filelock for quieter logging and handling of lock files (unix)."""

        # Quieten filelock's logger
        filelock.logger().setLevel(logging.CRITICAL)

        # filelock does not delete releasd lock files on Unix due
        # to potential race conditions in the event of multiple
        # programs trying to lock the file.
        # Refrapt only uses them to track whether a file was fully
        # downloaded or not in the event of interruption, so we
        # can cleanup the files now.
        for file in os.listdir(Settings.VarPath()):
            if ".lock" in file:
                os.remove(f"{Settings.VarPath()}/{file}")
Exemplo n.º 2
0
def main(pixiv_username, pixiv_password):
    #logging setup
    if not os.path.exists('logs'):
        os.makedirs('logs')
    logging.basicConfig(filename='logs/' +
                        datetime.datetime.now().strftime('%y-%m-%d_%H-%M') +
                        '.txt',
                        format='[%(asctime)s][%(levelname)s] %(message)s',
                        level=logging.DEBUG)
    filelock.logger().setLevel(logging.WARNING)
    #todo add logging

    app = QApplication(sys.argv)

    import builders
    builders.pixiv_username = pixiv_username
    builders.pixiv_password = pixiv_password

    if os.path.isfile('data.col'):
        cf = ColFile('data.col')
    else:
        cf = ColFile(QFileDialog.getOpenFileName()[0])
    cf.base_path = 'cols'
    cf.parse()
    cf.render()
    print('Ready')

    threading.Thread(target=render_loop, args=(cf, )).start()

    keyboard.add_hotkey('ctrl+alt+q', quit)
    keyboard.add_hotkey('ctrl+alt+x', close)
    keyboard.add_hotkey('ctrl+alt+s', set_save_flag, args=(True, ))

    while not quit_flag:
        global save_flag
        if save_flag:
            try:
                do_dialog(app, cf)
            finally:
                save_flag = False
        time.sleep(0.1)
Exemplo n.º 3
0
 def __init__(self, config):
     filelock.logger().disabled = True
     self.config = config
     self.debug = config.getboolean('nsh', 'debug')
     self.sleep = self.config.getfloat('nsh', 'sleep')
     self.gas_addr = self.get_gas_addr()
     self.trying = True
     os.makedirs(ROOT_LOG, exist_ok=True)
     self.lock = filelock.FileLock(ROOT_LOG + '.lock', self.sleep)
     try:
         self.lock.acquire()
         self.init0()
     except filelock.Timeout:
         while not os.path.exists(PATH_INDEX):
             self._print('waiting for the first index')
             time.sleep(self.sleep)
     self.index = _Problem.allocate_index()
     self.msg = self.create_msg()
     self.path_config = os.path.join(ROOT_LOG, f'config{self.index}.ini')
     with open(self.path_config, 'w') as f:
         self.config.write(f)
     atexit.register(lambda: os.system(
         '''killall -9 GasRunner; pkill -f "(lua|luajit) .+/start\.lua"'''))
     if config.getboolean('nsh', 'fake'):
         self.launch_fake_gas()
     else:
         if platform.system().lower() == 'windows':
             print('You must launch gas by yourself')
         else:
             self.launch_gas()
         self.tn = self.create_telnet()
         self.interface = self.get_interface()
         self._print(f'interface={self.interface}')
         self.tn(
             f'''SendServiceRpc({self.interface}, 'RunScript', [[g_ALDMgr:Start({self.index}, '{ROOT_LOG}', '{ROOT_PYTHON}')]])'''
         )
         self.tn(
             'SendServiceRpc(SA:Master(), "RunScript", "SERVICE_DOWN_CHECK_TIME = math.huge")'
         )
         self.tn(
             'SwitcherRpc_Send:RunScript(g_ServiceMgr:GetSwitcherIS(),[[ SERVICE_DOWN_CHECK_TIME = math.huge ]])'
         )
     self._print('waiting for pid')
     self.pid = self.msg.receive()
     assert isinstance(self.pid, int), self.pid
     self._print(f'pid={self.pid}')
 def __init__(self, db, mode="r"):
     self.mode = mode
     self.f = None
     self.db = db
     self.lock = filelock.FileLock(HDF5Manager.LOCK_FILE, timeout=60 * 3)
     filelock.logger().setLevel(logging.ERROR)
Exemplo n.º 5
0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

import filelock

from guild import config
from guild import util

# filelock uses `info` level logging for acquire/release status - move
# this to debug level.
filelock.logger().info = filelock.logger().debug

Timeout = filelock.Timeout

RUN_STATUS = "run-status"


def Lock(name, timeout=-1, guild_home=None):
    guild_home = guild_home or config.guild_home()
    locks_dir = os.path.join(guild_home, "locks")
    util.ensure_dir(locks_dir)
    lock_path = os.path.join(locks_dir, name)
    return filelock.FileLock(lock_path, timeout)
Exemplo n.º 6
0
"""Internal store to keep consumed messages from Kafka on disk to keep short commit periods"""
import os
import sys
import time
import singer
import logging
import filelock
from filelock import FileLock

from .errors import InvalidBookmarkException

# Set filelock logging less werbose
filelock.logger().setLevel(logging.WARNING)


class LocalStore:
    # pylint: disable=too-many-arguments,too-many-instance-attributes
    def __init__(self,
                 directory,
                 topic,
                 prefix='tap-kafka-local-store-',
                 postfix='',
                 extension='db',
                 batch_size_rows=1000):
        """Initialize local storage

        :param directory: directory path
        :param topic: name of the local store
        :param prefix: Optional file name prefix
        :param postfix: Optional file name postfix
        :param extension: Optional file name extension
__version__ = "unknown"
from ._version import __version__

import logging

logging.basicConfig(level=logging.INFO,
                    format="%(levelname)-8s [%(name)s] %(message)s")
log = logging.getLogger(__name__)

import filelock

filelock.logger().setLevel("WARNING")

# from .data_retrieval import GOOGLE
from . import data_retrieval
from . import plot
from . import model
from .model import Cov19Model

from ._dev_helper import create_example_instance
Exemplo n.º 8
0
def disable_lock_logs():
    lock_logger = filelock.logger()
    lock_logger.setLevel(30)