sqlitemulti/sqlitemulti/sqlitemulti.py
def _execute(
        self,
        command: SqlCommand,
        sql: Union[str, list],
        params: Union[None, tuple, list] = None,
        commit: bool = False,
    ):
        """Generic queued command. Enqueues the request, and waits for the answer."""
        if params is None:
            # This is to avoid https://www.thedigitalcatonline.com/blog/2015/02/11/default-arguments-in-python/#default-arguments-evaluation
            # and https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
            params = tuple()
        if self._trigger_garbage_collector:
            self._run_garbage_collector()
        thread_id = str(get_ident())
        if self._verbose:
            print(f"Called from thread {thread_id}")
        if thread_id in self._result_queues:
            result_queue = self._result_queues[thread_id][0]
        else:
            if self._own_process:
                result_queue = Manager().Queue()
            else:
                result_queue = Queue()
            with self._result_queues_lock:
                # Queue, expiration timestamp
                self._result_queues[thread_id] = (result_queue, time() + OLD_QUEUE_TRIGGER)
        # TODO: we should update the timestamp of the result queue to keep it active from GC.
        # Will systematic calls to time() for every _execute induce significant perfs losses?

        queue_index = self._current_queue  # What command queue to use?
        if self._tasks > 1:
            with self._lock:
                self._current_queue += 1
                if self._current_queue >= self._tasks:
                    self._current_queue = 0
                queue_index = self._current_queue
        # Enqueue the command
        self._command_queues[queue_index].put(
            (result_queue, command, sql, params, commit)
        )
        # And wait for its answer
        if self._verbose:
            print("Waiting...")
        res = result_queue.get()
        result_queue.task_done()
        return res
Generic queued command. Enqueues the request, and waits for the answer.
Generic queued command. Enqueues the request, and waits for the answer.
Generic queued command . Enqueues the request and waits for the answer .
def _execute(
        self,
        command: SqlCommand,
        sql: Union[str, list],
        params: Union[None, tuple, list] = None,
        commit: bool = False,
    ):
        if params is None:
            params = tuple()
        if self._trigger_garbage_collector:
            self._run_garbage_collector()
        thread_id = str(get_ident())
        if self._verbose:
            print(f"Called from thread {thread_id}")
        if thread_id in self._result_queues:
            result_queue = self._result_queues[thread_id][0]
        else:
            if self._own_process:
                result_queue = Manager().Queue()
            else:
                result_queue = Queue()
            with self._result_queues_lock:
                self._result_queues[thread_id] = (result_queue, time() + OLD_QUEUE_TRIGGER)
        queue_index = self._current_queue  
        if self._tasks > 1:
            with self._lock:
                self._current_queue += 1
                if self._current_queue >= self._tasks:
                    self._current_queue = 0
                queue_index = self._current_queue
        self._command_queues[queue_index].put(
            (result_queue, command, sql, params, commit)
        )
        if self._verbose:
            print("Waiting...")
        res = result_queue.get()
        result_queue.task_done()
        return res
def _execute ( self , command : SqlCommand , sql : Union [ str , list ] , params : Union [ None , tuple , list ] = None , commit : bool = False , ) : if params is None : params = tuple ( ) if self . _trigger_garbage_collector : self . _run_garbage_collector ( ) thread_id = str ( get_ident ( ) ) if self . _verbose : print ( f"Called from thread {thread_id}" ) if thread_id in self . _result_queues : result_queue = self . _result_queues [ thread_id ] [ 0 ] else : if self . _own_process : result_queue = Manager ( ) . Queue ( ) else : result_queue = Queue ( ) with self . _result_queues_lock : self . _result_queues [ thread_id ] = ( result_queue , time ( ) + OLD_QUEUE_TRIGGER ) queue_index = self . _current_queue if self . _tasks > 1 : with self . _lock : self . _current_queue += 1 if self . _current_queue >= self . _tasks : self . _current_queue = 0 queue_index = self . _current_queue self . _command_queues [ queue_index ] . put ( ( result_queue , command , sql , params , commit ) ) if self . _verbose : print ( "Waiting..." ) res = result_queue . get ( ) result_queue . task_done ( ) return res
Generic queued command.
Generic queued command .
"""Generic queued command. Enqueues the request, and waits for the answer.""" # This is to avoid https://www.thedigitalcatonline.com/blog/2015/02/11/default-arguments-in-python/#default-arguments-evaluation # and https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments # Queue, expiration timestamp # TODO: we should update the timestamp of the result queue to keep it active from GC. # Will systematic calls to time() for every _execute induce significant perfs losses? # What command queue to use? # Enqueue the command # And wait for its answer
self
command
SqlCommand
sql
Union[str, list]
params
Union[None, tuple, list]
commit
bool