當前位置: 首頁>>代碼示例>>Python>>正文


Python queue.Queue類代碼示例

本文整理匯總了Python中pq.queue.Queue的典型用法代碼示例。如果您正苦於以下問題:Python Queue類的具體用法?Python Queue怎麽用?Python Queue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Queue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

 def setUp(self):
     self.q = Queue()
     # pre-call this so we don't need to use multi-process
     # otherwise this is called within the classmethod
     PQ.listen('default', ['default'])
     # Fire off a notification of a fake job enqueued
     self.q.notify(1)
開發者ID:vladignatyev,項目名稱:django-pq,代碼行數:7,代碼來源:test_queue.py

示例2: handle

    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        verbosity = int(options.get('verbosity', 1))
        func = args[0]
        args = args[1:]
        async = not options.get('sync')
        timeout = options.get('timeout')
        queue = options.get('queue')
        conn = options.get('conn')
        if options['serial']:
            queue = queue or 'serial'
            q = SerialQueue.create(queue, connection=conn)
        else:
            queue = queue or 'default'
            q = Queue.create(queue, connection=conn)
        if timeout:
            job = q.enqueue_call(func, args=args, timeout=timeout, async=async)
        else:
            job = q.enqueue_call(func, args=args, async=async)
        if verbosity and job.id:
            print('Job %i created' % job.id)
        elif verbosity:
            print('Job complete')
開發者ID:oinopion,項目名稱:django-pq,代碼行數:28,代碼來源:pqenqueue.py

示例3: handle

    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.

        """
        from django.conf import settings
        from pq.queue import Queue, SerialQueue
        from pq.worker import Worker

        sentry_dsn = options.get('sentry_dsn')
        if not sentry_dsn:
            sentry_dsn = settings.SENTRY_DSN if hasattr(settings, 'SENTRY_DSN') else None

        verbosity = int(options.get('verbosity'))
        queues = []
        for queue in args:
            q = Queue.objects.get(name=queue)
            if q.serial:
                queues.append(SerialQueue.create(name=queue))
            else:
                queues.append(Queue.create(name=queue))
        w = Worker.create(queues, name=options.get('name'), connection=options['connection'])

        # Should we configure Sentry?
        if sentry_dsn:
            from raven import Client
            from pq.contrib.sentry import register_sentry
            client = Client(sentry_dsn)
            register_sentry(client, w)

        w.work(burst=options['burst'])
開發者ID:vilos,項目名稱:django-pq,代碼行數:32,代碼來源:pqworker.py

示例4: test_queue_creation_conflict_issue2

 def test_queue_creation_conflict_issue2(self):
     """Ordinary queue shouldn't ever become a serial queue"""
     q = Queue.create()
     self.assertFalse(q.serial)
     q.enqueue(do_nothing)
     self.q.enqueue(do_nothing)
     w = Worker([q, self.q])
     w.work(burst=True)
開發者ID:vladignatyev,項目名稱:django-pq,代碼行數:8,代碼來源:test_queue_serial.py

示例5: handle

    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        verbosity = int(options.get('verbosity', 1))
        func = args[1]
        if args[0].lower() == 'now':
            at = now()
        else:
            at = parser.parse(args[0])
        if not at.tzinfo:
            at = at.replace(tzinfo=get_default_timezone())

        args = args[2:]
        if options.get('mtwtf'):
            weekdays = (0, 1, 2, 3, 4)
        else:
            weekdays = (
                options.get('mo'),
                options.get('tu'),
                options.get('we'),
                options.get('th'),
                options.get('fr'),
                options.get('sa'),
                options.get('su'),
            )

            weekdays = [w for w in weekdays if isinstance(w, integer_types)]
        timeout = options.get('timeout')
        queue = options.get('queue')
        conn = options.get('conn')
        if options['serial']:
            queue = queue or 'serial'
            q = SerialQueue.create(queue, connection=conn, scheduled=True)
        else:
            queue = queue or 'default'
            q = Queue.create(queue, connection=conn, scheduled=True)
        job = q.schedule_call(
            at, func,
            args=args,
            timeout=timeout,
            repeat=options['repeat'],
            interval=options['interval'],
            between=options['between'],
            weekdays=weekdays
        )
        if verbosity:
            print('Job %i created' % job.id)
開發者ID:oinopion,項目名稱:django-pq,代碼行數:51,代碼來源:pqschedule.py

示例6: pq

def pq(function, *args, **kwargs):
    '''
    Adds ``function`` to the `django-pq <https://github.com/bretth/django-pq>`_
    default queue, with any passed in
    ``args`` and ``kwargs`` It will create this queue if it doesn't exist.
    '''
    from pq.queue import Queue
    queue = Queue.create()
    # Try to create the queue table, but if the database isn't set up yet
    # then don't create it
    try:
        queue.save()
    except DatabaseError:
        pass

    queue.enqueue(function, *args, **kwargs)
開發者ID:vccabral,項目名稱:django-simpleimages,代碼行數:16,代碼來源:callers.py

示例7: handle

 def handle(self, *args, **options):
     """
     The actual logic of the command. Subclasses must implement
     this method.
     """
     from pq.queue import Queue, SerialQueue
     verbosity = int(options.get('verbosity', 1))
     timeout = options.get('timeout')
     for queue in args:
         if options['serial']:
             q = SerialQueue.create(queue)
         else:
             q = Queue.create(queue)
         q.connection = options.get('conn')
         q.scheduled = options.get('scheduled')
         if timeout:
             q.default_timeout = timeout
         q.save()
開發者ID:JirkaV,項目名稱:django-pq,代碼行數:18,代碼來源:pqcreate.py

示例8: handle

    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        func = args[1]
        if args[0].lower() == 'now':
            at = now()
        else:
            at = parser.parse(args[0])
        if not at.tzinfo:
            at = at.replace(tzinfo=get_default_timezone())

        args = args[2:]
        if options.get('mtwtf'):
            weekdays = (0,1,2,3,4)
        else:
            weekdays = (
                options.get('mo'),
                options.get('tu'),
                options.get('we'),
                options.get('th'),
                options.get('fr'),
                options.get('sa'),
                options.get('su'),
                )
            weekdays = [w for w in weekdays if w]
        timeout = options.get('timeout')
        queue = options.get('queue')
        if options['serial']:
            queue = queue or 'serial'
            q = SerialQueue.create(queue)
        else:
            queue = queue or 'default'
            q = Queue.create(queue)
        q.schedule_call(at, func, args=args, 
            timeout=timeout,
            repeat=options['repeat'],
            interval=options['interval'],
            between=options['between'],
            weekdays=weekdays
            )
開發者ID:vilos,項目名稱:django-pq,代碼行數:44,代碼來源:pqschedule.py

示例9: handle

    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        func = args[0]
        args = args[1:]
        timeout = options.get("timeout")
        queue = options.get("queue")
        if options["serial"]:
            queue = queue or "serial"
            q = SerialQueue.create(queue)
        else:
            queue = queue or "default"
            q = Queue.create(queue)
        if timeout:
            q.enqueue(func, *args, timeout=timeout)
        else:
            q.enqueue(func, *args)
開發者ID:vilos,項目名稱:django-pq,代碼行數:21,代碼來源:pqenqueue.py

示例10: test_validated_name

 def test_validated_name(self, name):
     with self.assertRaises(InvalidQueueName):
         PQ.validated_name(name)
開發者ID:vladignatyev,項目名稱:django-pq,代碼行數:3,代碼來源:test_queue.py

示例11: test_dequeue_any_serial_lock

 def test_dequeue_any_serial_lock(self):
     """Test that it raises a DequeueTimeout timeout"""
     with self.assertRaises(DequeueTimeout):
         Queue.dequeue_any([self.sq], timeout=1)
開發者ID:vladignatyev,項目名稱:django-pq,代碼行數:4,代碼來源:test_queue_serial.py

示例12: test_default_queue_create_multiple

 def test_default_queue_create_multiple(self):
     queue = Queue.create()
     self.assertEqual(queue.name, 'default')
     queue = SerialQueue.create()
     self.assertEqual(queue.name, 'default (serial)')
開發者ID:vladignatyev,項目名稱:django-pq,代碼行數:5,代碼來源:test_queue_serial.py

示例13: test_dequeue_any_serial

 def test_dequeue_any_serial(self):
     job, queue = Queue.dequeue_any([self.sq], timeout=10)
     self.assertEquals(job.func, do_nothing)
開發者ID:vladignatyev,項目名稱:django-pq,代碼行數:3,代碼來源:test_queue_serial.py

示例14: test_dequeue_any_multiple

    def test_dequeue_any_multiple(self):
        job, queue = PQ.dequeue_any([self.fooq, self.barq], None)
        self.assertEqual(queue, self.fooq)
        self.assertEqual(job.func, say_hello)
        self.assertEqual(job.origin, self.fooq.name)
        self.assertEqual(
            job.args[0], 'for Foo', 'Foo should be dequeued first.')

        job, queue = PQ.dequeue_any([self.fooq, self.barq], None)
        self.assertEqual(queue, self.barq)
        self.assertEqual(job.func, say_hello)
        self.assertEqual(job.origin, self.barq.name)
        self.assertEqual(
            job.args[0], 'for Bar', 'Bar should be dequeued second.')
開發者ID:oinopion,項目名稱:django-pq,代碼行數:14,代碼來源:test_queue.py

示例15: test_quarantine_job

    def test_quarantine_job(self):
        """Requeueing existing jobs."""

        get_failed_queue().quarantine(
            self.job, Exception('Some fake error'))  # noqa
        self.assertEqual(sorted(PQ.all()), sorted([get_failed_queue()]))  # noqa
        self.assertEqual(get_failed_queue().count, 1)
開發者ID:oinopion,項目名稱:django-pq,代碼行數:7,代碼來源:test_queue.py


注:本文中的pq.queue.Queue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。