From 6578b5b9250224872612aa338c20622056dcba68 Mon Sep 17 00:00:00 2001 From: anand k Date: Sun, 23 Jun 2024 08:43:51 +0530 Subject: [PATCH] Moved multiqueue to network module --- src/{ => network}/multiqueue.py | 9 ++------- src/queues.py | 7 +++---- src/tests/test_multiqueue.py | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) rename src/{ => network}/multiqueue.py (89%) diff --git a/src/multiqueue.py b/src/network/multiqueue.py similarity index 89% rename from src/multiqueue.py rename to src/network/multiqueue.py index 88b6a4dd..3fad4e34 100644 --- a/src/multiqueue.py +++ b/src/network/multiqueue.py @@ -2,16 +2,11 @@ A queue with multiple internal subqueues. Elements are added into a random subqueue, and retrieval rotates """ - +import random from collections import deque from six.moves import queue -try: - import helper_random -except ImportError: - from . import helper_random - class MultiQueue(queue.Queue): """A base queue class""" @@ -38,7 +33,7 @@ class MultiQueue(queue.Queue): # Put a new item in the queue def _put(self, item): # self.queue.append(item) - self.queues[helper_random.randomrandrange(self.queueCount)].append( + self.queues[random.randrange(self.queueCount)].append( # nosec B311 (item)) # Get an item from the queue diff --git a/src/queues.py b/src/queues.py index 4a9b98d2..a95e8e46 100644 --- a/src/queues.py +++ b/src/queues.py @@ -5,10 +5,9 @@ import time from six.moves import queue -try: - from multiqueue import MultiQueue -except ImportError: - from .multiqueue import MultiQueue + +from network.multiqueue import MultiQueue + class ObjectProcessorQueue(queue.Queue): diff --git a/src/tests/test_multiqueue.py b/src/tests/test_multiqueue.py index 87149d56..4b041f1c 100644 --- a/src/tests/test_multiqueue.py +++ b/src/tests/test_multiqueue.py @@ -1,7 +1,7 @@ """Test cases for multiqueue""" import unittest -from pybitmessage.multiqueue import MultiQueue +from pybitmessage.network.multiqueue import MultiQueue class TestMultiQueue(unittest.TestCase):