queue

python threads - always have x active threads when iterating over n tasks

烈酒焚心 提交于 2019-12-13 05:15:52
问题 What I basically want to do is the following: import threading import Queue def test_thread(elem, q): q.put(elem ** 2) a = [1,2,3,4,5,6,7,8] q = Queue.Queue() results = [] for x in range(8): print x threading.Thread(target=test_thread, args=(a[x], q)).start() results.append(q.get()) But instead of running all threads at once I want to run only say 2 in parallel adn iterate over the list. Once one thread is done the next value from the list should be processed. I could't find an example and I

Python 3 - Multiprocessing - Queue.get() does not respond

谁说我不能喝 提交于 2019-12-13 04:51:09
问题 I want to make a brute force attack and therefore need some speed... So I came up to use the multiprocessing library... However, in every tutorial I've found, something did not work.... Hm.. This one seems to work very well, except, that I whenever I call the get() function, idle seems to go to sleep and it doesn't respond at all. Am I just silly or what? I just copy pasted the example, so it should have worked.... import multiprocessing as mp import random import string # Define an output

How to create a job and queue in a grails application

旧街凉风 提交于 2019-12-13 04:38:41
问题 I have a grails application in which the user uploads a document and my application does various things with the uploaded file. Some of these tasks take a long time so the user has to wait to see the next page. I want to change this behavior such that the user uploads the file and then immediately sees the next page. In the background the uploaded file will be queued. Later I want to pick-up files from the queue and process them in the order they were received. What are some options available

C++ Car Simulation

一曲冷凌霜 提交于 2019-12-13 04:18:27
问题 C++ Data Structures using Queue, My code output is not correct, I am not sure what to change. C++ using the stl Queue library, I am having trouble getting the correct output from my program. The wait time is not being displayed correctly and the start time of the wash is not being displayed correctly. This is the code I have so far: #include <iostream> #include <assert.h> #include <fstream> #include <queue> #include <stdlib.h> using namespace std; class averager { private: int cnt; int sum;

No onMessage events on Runtime (Java JMS MessageListener on Oracle Queue)

只愿长相守 提交于 2019-12-13 04:18:16
问题 Purpose I created MyListener.java to monitor my Oracle Queue MY_QUEUE and MyConsumer.java implement my own MessageListener.onMessage functionality. As soon as I enqueue some entries into MY_QUEUE I want the MessageListener to output "New Message..." onto the console. Problem The Queue entries will only be processed on the initial application start. If additional entries get enqueued while the application is already runnning the MessageListener.onMessage function won't get triggered. Example

Laravel 5.7 : Supervisorctl does not auto-restart queue worker with

那年仲夏 提交于 2019-12-13 03:56:26
问题 I have supervisor for managing queue notifications as suggested in the laravel documentation . I have configured the supervisor as per the documentation and here is my configuration file. [program:laravel-worker] process_name=%(program_name)s_%(process_num)02d command=php /var/www/application/artisan queue:work --tries=3 autostart=true autorestart=true user=root numprocs=8 redirect_stderr=true stdout_logfile=/var/www/application/storage/logs/worker/worker.log This works fine but the problem

Queue in and out according to clients’type

邮差的信 提交于 2019-12-13 03:43:41
问题 Queue in and out according to clients’type Question Based on previous implementation, modify the LIST command, so that it will print VIP clients first then ordinary clients in ascending order by queue number. Same as OUT command, VIP will be queued out first then ordinary clients. Input IN 1000001 Ordinary IN 2000003 VIP IN 2000009 VIP OUT OUT OUT OUT IN 1000007 Ordinary IN 2000005 VIP LIST OUT QUIT Output IN:1 1000001 Ordinary 0 IN:2 2000003 VIP 0 IN:3 2000009 VIP 1 OUT:2 2000003 VIP OUT:3

Using BFS to compute distance between a source and a vertex

家住魔仙堡 提交于 2019-12-13 03:33:29
问题 I am trying to use adjacency list to compute the distance from a source vertex to the other vertices. I am using a queue to accomplish this however I get the distance of each vertex besides the source as -1, but I am not sure why this is happening #include <stdio.h> #include <stdlib.h> #include "input_error.h" #define VertexToSearch 1 typedef struct edge { int vertexIndex; struct edge *edgePtr; } edge; typedef struct vertex { int vertexKey; struct edge *edgePtr; int visited; int distance; }

Nonblocking queue of threads

送分小仙女□ 提交于 2019-12-13 03:29:46
问题 I want to create simple queue of threads. THREADS WILL START WITH POST REQUEST I created simple example without requests. I tried to join threads, but it doesn't work as i want. def a(): print('start a') sleep(5) print('end a') def b(): print('start b') sleep(5) print('end b') t = Thread(target=a) t.start() t.join() print('test1') t = Thread(target=b) t.start() t.join() print('test2') Result of code: start a end a test1 start b end b test2 Expectation: start a test1 end a start b test2 end b

Dequeue from Queue with where expression

浪子不回头ぞ 提交于 2019-12-13 03:29:28
问题 I have a blocking queue class based on Marc Gravell's Blocking Queue Now I have situations where I want to dequeue only a certain object, I know this is not really the use case of a queue, but in some cases I think this is a good extension, for example waiting for a certain network answer. This would be something like a TryDequeueWhere(Func<T, bool> expression, out T value, int? waitTimeInMs = null) The problem is I don't know how to wait and block for a certain object. 回答1: After posting my