This commit is contained in:
emdee 2022-10-12 19:51:08 +00:00
parent d2fe721072
commit a92bbbbcbf
5 changed files with 60 additions and 11 deletions

View file

@ -488,7 +488,7 @@ class App:
LOG.debug(f"_start_threads init: {te()!r}")
# starting threads for tox iterate and toxav iterate
self._main_loop = threads.ToxIterateThread(self._tox)
self._main_loop = threads.ToxIterateThread(self._tox, self)
self._main_loop.start()
self._av_loop = threads.ToxAVIterateThread(self._tox.AV)
@ -849,7 +849,7 @@ class App:
self.test_net()
self._ms.log_console()
def test_net(self, lElts=None, oThread=None, iMax=4):
def test_net(self, oThread=None, iMax=4):
LOG.debug("test_net " +self._oArgs.network)
# bootstrap
@ -905,6 +905,9 @@ class App:
LOG.trace(f"Connected status #{i}: {status!r}")
self.loop(2)
global iLAST_CONN
iLAST_CONN = time.time()
def _test_env(self):
_settings = self._settings
if 'proxy_type' not in _settings or _settings['proxy_type'] == 0 or \

View file

@ -3,7 +3,6 @@ from sqlite3 import connect
import os.path
import utils.util as util
# LOG=util.log
global LOG
import logging
LOG = logging.getLogger('app.db')

View file

@ -1,6 +1,10 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from history.history_logs_generators import *
global LOG
import logging
LOG = logging.getLogger('app.db')
class History:
def __init__(self, contact_provider, db, settings, main_screen, messages_items_factory):

View file

@ -6,6 +6,7 @@ from PyQt5 import QtCore
from bootstrap.bootstrap import *
from bootstrap.bootstrap import download_nodes_list
from wrapper.toxcore_enums_and_consts import TOX_USER_STATUS, TOX_CONNECTION
import wrapper_tests.support_testing as ts
from utils import util
@ -36,6 +37,9 @@ def LOG_INFO(l): print('INFO+ '+l)
def LOG_DEBUG(l): print('DBUG+ '+l)
def LOG_TRACE(l): pass # print('TRACE+ '+l)
iLAST_CONN = 0
iLAST_DELTA = 60
# -----------------------------------------------------------------------------------------------------------------
# Base threads
# -----------------------------------------------------------------------------------------------------------------
@ -117,7 +121,7 @@ class InitThread(BaseThread):
threading.Timer(1.0,
self._app.test_net,
args=list(),
kwargs=dict(lElts=None, oThread=self, iMax=2)
kwargs=dict(oThread=self, iMax=4)
).start()
if self._is_first_start:
@ -136,9 +140,10 @@ class InitThread(BaseThread):
class ToxIterateThread(BaseQThread):
def __init__(self, tox):
def __init__(self, tox, app=None):
super().__init__()
self._tox = tox
self._app = app
def run(self):
LOG_DEBUG('ToxIterateThread run: ')
@ -150,7 +155,30 @@ class ToxIterateThread(BaseQThread):
# Fatal Python error: Segmentation fault
LOG_ERROR(f"ToxIterateThread run: {e}")
else:
sleep(iMsec / 1000)
sleep(iMsec / 1000.0)
global iLAST_CONN
if not iLAST_CONN:
iLAST_CONN = time.time()
# TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
# and segv
if \
time.time() - iLAST_CONN > iLAST_DELTA and \
ts.bAreWeConnected() and \
self._tox.self_get_status() == TOX_USER_STATUS['NONE'] and \
self._tox.self_get_connection_status() == TOX_CONNECTION['NONE']:
iLAST_CONN = time.time()
LOG_INFO(f"ToxIterateThread calling test_net")
if True:
invoke_in_main_thread(
self._app.test_net, oThread=self, iMax=2)
else:
threading.Timer(1.0,
self._app.test_net,
args=list(),
kwargs=dict(lElts=None, oThread=self, iMax=2)
).start()
class ToxAVIterateThread(BaseQThread):

View file

@ -17,6 +17,20 @@ from ctypes import *
from utils import util
from utils import ui as util_ui
# callbacks can be called in any thread so were being careful
# tox.py can be called by callbacks
def LOG_ERROR(a): print('EROR> '+a)
def LOG_WARN(a): print('WARN> '+a)
def LOG_INFO(a):
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 20
if bVERBOSE: print('INFO> '+a)
def LOG_DEBUG(a):
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 10-1
if bVERBOSE: print('DBUG> '+a)
def LOG_TRACE(a):
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel < 10
if bVERBOSE: print('TRAC> '+a)
def tox_log_cb(iTox, level, file, line, func, message, *args):
"""
* @param level The severity of the log message.
@ -42,7 +56,7 @@ def tox_factory(data=None, settings=None, args=None, app=None):
:return: new tox instance
"""
if not settings:
LOG.warn("tox_factory using get_default_settings")
LOG_WARN("tox_factory using get_default_settings")
settings = user_data.settings.Settings.get_default_settings()
else:
user_data.settings.clean_settings(settings)
@ -88,13 +102,14 @@ def tox_factory(data=None, settings=None, args=None, app=None):
tox_options._options_pointer,
tox_options.self_logger_cb)
else:
logging.warn("No tox_options._options_pointer to add self_logger_cb" )
logging_WARN("No tox_options._options_pointer to add self_logger_cb" )
retval = wrapper.tox.Tox(tox_options)
except Exception as e:
if app and hasattr(app, '_log'):
app._log(f"ERROR: wrapper.tox.Tox failed: {e}")
LOG.warn(traceback.format_exc())
pass
LOG_ERROR(f"wrapper.tox.Tox failed: {e}")
LOG_WARN(traceback.format_exc())
raise
if app and hasattr(app, '_log'):