def e(message): """Error""" _log(Level.error, message) def clear(): """Clear and remove the log file""" with _log_lock: _close_log_file() if os.path.isfile(_log_file_path): os.remove(_log_file_path) _var_dir = env.get_var_dir() env.make_dirs(_var_dir) _log_file = env.get_log_file() _log_file_path = os.path.join(_var_dir, _log_file) _f = None _log_lock = threading.Lock() def _log(level: Level, message): with _log_lock: s = '[{}] {}({}): {}'.format( time.ctime(), level.value, threading.current_thread().name, message
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import threading import os import sqlite3 import env _var_dir = env.get_var_dir() env.make_dirs(_var_dir) _db_file = env.get_db_file() _db_file_path = os.path.join(_var_dir, _db_file) # Task and result _func = None _result = None # Synchronization _exec_lock = threading.Lock() _task_event = threading.Event() _result_event = threading.Event() _shutting_down = False
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os import socket import subprocess import sys import env import logger from core.threads import ServerThread env.make_dirs(env.get_var_dir()) _lock_file_path = os.path.join(env.get_var_dir(), env.get_lock_file()) def start(): """Start daemon process""" if os.path.isfile(_lock_file_path): print('Error: Server already started') else: args = sys.executable, __file__ pid = _start_daemon(args).pid print('Server started with PID {}'.format(pid)) with open(_lock_file_path, 'w') as f: f.write(str(pid))