queue

Using many consumers in SQS Queue

倖福魔咒の 提交于 2019-12-27 11:47:43
问题 I know that it is possible to consume a SQS queue using multiple threads. I would like to guarantee that each message will be consumed once. I know that it is possible to change the visibility timeout of a message, e.g., equal to my processing time. If my process spend more time than the visibility timeout (e.g. a slow connection) other thread can consume the same message. What is the best approach to guarantee that a message will be processed once? 回答1: What is the best approach to guarantee

How I sort list with enqueue function in c?

故事扮演 提交于 2019-12-25 17:36:27
问题 My list : list= C,3 -->C,5,---> A,7 --> A,5 --> G,2--> C,11 -->A,4 my outuput : output= C,5 C,11 G,2 A,7 A,4 A,5 C,3 but there is some mistakes. I write my code like in answers and I write charcmp function and replace with strcmp with charcmp. It works sometime corrcectly. But usually first element is in the wrong place .My sorting code likes answer's code 回答1: The following code should do the work. It will add to the list in increasing age order: #include <stdio.h> #include <stdlib.h>

dispatch_queue and return data

跟風遠走 提交于 2019-12-25 16:42:57
问题 I'm trying to write this method that returns an NSArray . My NSMutableArray (friendUsers) adds the objects right, but outside the dispatch_async the array is empty. I try to add the users in the main queue ( as ashowed) but the array is empty to. Any ideas ? Thanks for all your help. - (NSArray *)checkUsersInGroup { NSMutableArray *friendUsers = [[NSMutableArray alloc] init]; dispatch_queue_t checkUSers = dispatch_queue_create("CheckUsers", NULL); dispatch_async(checkUSers, ^{ NSArray

Python redis subscribe can not get all datas?

99封情书 提交于 2019-12-25 08:49:43
问题 I am using python to get datas from redis and then parser it to kafka. It works well in most situations. But when I use python to simulate build the data to redis, or there was a fast put-in datas in queuen, I can't get all the data. Here is my code about redis producer to simulate build 20000 datas to redis: rc = redis.Redis(host='127.0.0.1', port=6379) rc.ping() ps = rc.pubsub() ps.subscribe('bdwaf') r_str = "--8198b507-A--\n[22/Jun/2017:14:13:19 +0800]ucTcxcMcicAcAcAcicAcAcAm 192.168.1.189

Making a queue program

瘦欲@ 提交于 2019-12-25 05:19:10
问题 Can someone help me making a queue program. I want to set the array[0] to be array[1] just in display but in real I am adding value at array[0] . I got how to run the add function to it, but I can't do the view and delete command that will view from ex. array[0] to array[4], when displayed array[1] to array[5] with the value inserted. #include <stdio.h> #include <stdlib.h> #define p printf #define s scanf int rear = 0; int front = 0; int *q_array = NULL; int size = 0; main() { int num, opt;

Making a queue program

时光总嘲笑我的痴心妄想 提交于 2019-12-25 05:19:09
问题 Can someone help me making a queue program. I want to set the array[0] to be array[1] just in display but in real I am adding value at array[0] . I got how to run the add function to it, but I can't do the view and delete command that will view from ex. array[0] to array[4], when displayed array[1] to array[5] with the value inserted. #include <stdio.h> #include <stdlib.h> #define p printf #define s scanf int rear = 0; int front = 0; int *q_array = NULL; int size = 0; main() { int num, opt;

Finding the max of each continguous subarray of a given size

醉酒当歌 提交于 2019-12-25 04:29:35
问题 I'm trying to solve the following problem in Python Given an array and an integer k, find the maximum for each and every contiguous subarray of size k. The idea is to use a double ended queue. This is my code: def diff_sliding_window(arr, win): # max = -inf Q = [] win_maxes = [] # max of each window for i in range(win): print(Q) while len(Q) > 0 and arr[i] >= arr[len(Q) - 1]: # get rid of the index of the smaller element Q.pop() # removes last element Q.append(i) # print('>>', Q) for i in

inserting into a queue while enumerating it

百般思念 提交于 2019-12-25 01:48:12
问题 I want to do a breadth first search of a tree using a Queue var q = new Queue<T>(); q.Enqueue(Root); foreach(T root in q) { foreach(T t in root.Children) q.Enqueue(t); } However I get a "Collection was modified after the enumerator was instantiated." Exception. Is there a C# type that I can do this with? Edit: a little reading make me thing I might be doing this totally wrong. Is there a way to use a foreach to dequeue from a Queue? this works but is ugly (OMHO) var q = new Queue<T>(); q

Python in Linux: Put user input asynchronously into queue

浪子不回头ぞ 提交于 2019-12-25 01:44:01
问题 I am trying to run a program that takes in input as a job is getting done. I have looked through several forms, and looked into the documentation. I'm running this in Debian, and I understand that I can use this getch function to receive characters without hitting the return key. To break it down, this is what I am trying to implement in my infinite while loop Take in input (threading didn't work here for me Put input into Queue If there are no running jobs, start the job with the item in

Laravel multiple workers running job twice

北战南征 提交于 2019-12-25 00:41:30
问题 I am using Laravel 5.6 and I am dispatching jobs to a queue and then using supervisor to activate 8 workers on that queue. I was expecting that Laravel will know NOT to run the same job twice but I was surprised to discover that it did. Same job was taken cared of by more than one worker and therefore weird stuff started to happen. The thing is that one year ago I wrote the same mechanism for another Laravel project (but on Laravel version 5.1) and the whole thing worked out of the box. I