标签: queue

如何从文件中的列表运行第一个进程,删除第一行,就好像该文件是一个队列并且我调用“pop”一样?

如何从存储在文件中的进程列表中运行第一个进程并立即删除第一行,就好像该文件是一个队列并且我调用了“pop”一样?

我想以类似流行的方式调用简单文本文件中列出的第一个命令,并使用 \n 作为分隔符:

图1:

cmdqueue.lst :

proc_C1
proc_C2
proc_C3
.
.
Run Code Online (Sandbox Code Playgroud)

图2:

通过以下方式弹出第一个命令popcmd:

proc_A | proc_B | popcmd cmdqueue.lst | proc_D
Run Code Online (Sandbox Code Playgroud)

图3:

cmdqueue.lst :

proc_C2
proc_C3
proc_C4
.
.
Run Code Online (Sandbox Code Playgroud)

unix queue shell

3
推荐指数
1
解决办法
1040
查看次数

如何使用两个堆栈实现双端队列

Deque(“双端队列”)操作、入队和出队都可以从两端进行。

如何使用 2 个堆栈为双端队列定义ADT操作?

实施还应该考虑性能。

queue stack deque data-structures

3
推荐指数
1
解决办法
1万
查看次数

具有并发工作者的 RxJS 并行队列?

假设我想下载 10,000 个文件。我可以轻松地构建一个包含这 10,000 个文件的队列(如果其中任何一个可以做得更好,我很乐意接受建议),

import request from 'request-promise-native';
import {from} from 'rxjs';

let reqs = [];
for ( let i = 0; i < 10000; i++ ) {
  reqs.push(
    from(request(`http://bleh.com/${i}`))
  )
};
Run Code Online (Sandbox Code Playgroud)

现在我有一个 Rx.JS observable 数组,我是从代表我的队列的承诺中创建的。现在对于我想要的行为,我想发出

  • 三并发请求到服务器
  • 完成请求后,我希望触发新的请求。

我可以为这个问题创建一个解决方案,但鉴于我从未使用过的Rxjs queue 之类的东西,我想知道最正确的 Rxjs 方法是什么。

queue parallel-processing rxjs concurrent-queue

3
推荐指数
1
解决办法
1268
查看次数

使用 redis 在 laravel 中排队

我在一个应用程序中遇到了问题,我在后端进行了很多 api 调用。因此,应用程序收到超时错误。

有人建议我应该使用队列。我试图用 redis 这样做。该函数进入工作并使用处理程序,但我希望页面加载我给它的数据,而没有来自 api 的数据,而 api 调用正在后台进行。相反,它就像我没有使用队列时一样。我试图按照教程来做到这一点,但他们做的并不完全一样,我无法调整它所以它对我有用。

有关我在工作中做什么的信息。我得到了一个 csv 的评论,我使用评论中的数字来调用 api,我得到了一个 8-10 个字段的 json。我需要调用 api 大约 650 次,所以当我想将数据保存到数据库时需要很长时间。我一次使用一个插入来使用“缓存”,所以我不会两次执行相同的调用。

这是我调用工作的控制器。

class ImportController extends Controller
{
public function checkErrors(Request $request)
{
    $this->checkAgainstDocuments($csv_id);
    $supplierErrorIds=$this->checkSupplierErrors($parameters, $company , $csv_id);
    $timesheetErrors=TsData::whereIn('id', $supplierErrorIds)->sortable()->paginate(20);
    return view('show_errors', compact('timesheetErrors', 'company', 'csv_id'));
}

public function checkAgainstDocuments($csv_id)
{
    GetFromDocumentsAPI::dispatch($csv_id)->delay(now()->addMinutes(10));
}
}
Run Code Online (Sandbox Code Playgroud)

这是我使用的工作:

class GetFromDocumentsAPI implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $csv_id;
/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($csv_id) …
Run Code Online (Sandbox Code Playgroud)

php queue redis laravel

3
推荐指数
1
解决办法
1万
查看次数

NodeJS如何在该作业失败后的特定时间内使用公牛重试队列作业

我正在尝试创建一个作业,该作业将在使用bull queue. 但工作从不拖延,总是紧随其后。这是我当前的代码:

const Queue = require('bull');
const queue = new Queue('send notiffication to main app', 'redis://127.0.0.1:6379');
const sendDepositNotificationToMainAppJob = require('../jobs/sendDepositNotificationToMainApp');

 queue.process(new sendDepositNotificationToMainAppJob(depositSuccess));

Run Code Online (Sandbox Code Playgroud)

sendDepositNotificationToMainApp.js

const Queue = require('bull');
const queue = new Queue('send notif to main app', 'redis://127.0.0.1:6379');
class sendDepositNotificationToMainApp {
    constructor(depositSuccess){
        return handle(depositSuccess);
    }
}

const handle = async (depositSuccess) => {
  try {
   //some function here
   }.catch(e){
     //if error retry job here 
      queue.add(new sendDepositNotificationToMainApp(depositSuccess), {delay : 5000})
   }

}

module.exports = sendDepositNotificationToMainApp;

Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

queue jobs node.js

3
推荐指数
1
解决办法
7899
查看次数

是否有像 Queue 这样的 C# 类实现 IAsyncEnumerable?

两者Queue和ConcurrentQueue实施IEnumerable但不是IAsyncEnumerable。NuGet 上是否有可用的标准类或类来实现IAsyncEnumerable,如果队列为空,则在将MoveNextAsync下一个添加到队列之前,结果不会完成?

c# queue asynchronous iasyncenumerable

3
推荐指数
1
解决办法
723
查看次数

Python asyncio 不显示任何错误

我正在尝试使用 asyncio 从数千个 url 中获取一些数据。以下是该设计的简要概述:

  1. Queue一次性填写一堆网址Producer
  2. 产生一堆 Consumers
  3. 每个都Consumer保持异步从请求中提取 urlQueue并发送GET请求
  4. 对结果做一些后处理
  5. 合并所有处理结果并返回

问题: asyncio几乎从不显示是否有任何问题,它只是默默地挂起而没有错误。我在print各处放置语句来自己检测问题,但这并没有多大帮助。

根据输入网址的数量和消费者的数量或限制,我可能会收到以下错误:

  1. Task was destroyed but it is pending!
  2. task exception was never retrieved future: <Task finished coro=<consumer()
  3. aiohttp.client_exceptions.ServerDisconnectedError
  4. aiohttp.client_exceptions.ClientOSError: [WinError 10053] An established connection was aborted by the software in your host machine

问题:如何检测和处理中的异常asyncio?如何在不中断的情况下重试Queue?

Bellow 是我在查看异步代码的各种示例时编译的代码。目前,def get_video_title函数末尾存在故意错误。运行时,什么都不显示。

import asyncio
import aiohttp
import json
import re
import nest_asyncio
nest_asyncio.apply() …
Run Code Online (Sandbox Code Playgroud)

python queue exception python-asyncio aiohttp

3
推荐指数
1
解决办法
1446
查看次数

如何将 stl 队列推送函数绑定到 std::function?

我试过这个

{
    std::function<void(int)> push;
    queue<int> myqueue; 
    push = std::bind(static_cast<void (queue<int>::*)(int)>(&queue<int>::push), &myqueue,std::placeholders::_1);
    push(8);
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用

c++ queue bind std-function

3
推荐指数
1
解决办法
109
查看次数

类型错误:无法pickle 'weakref' 对象

这里的多处理相当新。我有一个运行两个进程的代码。一种是不断地从服务器接收数据块并将其放入队列中,另一种是从队列中取出数据块并对其进行处理。

下面是我的客户端代码:


import socket
import turtle
import multiprocessing
from multiprocessing import Process, Queue
from tkinter import *


class GUI:

    def __init__(self, master):
        rec_data = recv_data()
        self.master = master
        master.title("Collision Detection")

        self.input_label = Label(root, text="Input all the gratings set straight wavelength values in nm")
        self.input_label.grid(row=0)

        self.core_string = "Core "
        self.entries = []


        self.label_col_inc = 0
        self.entry_col_inc = 1
        self.core_range = range(1, 5)

        for y in self.core_range:
            self.core_text = self.core_string + str(y) + '_' + '25'
            self.core_label = Label(root, text=self.core_text)
            self.entry = …
Run Code Online (Sandbox Code Playgroud)

python queue tcp tkinter multiprocessing

3
推荐指数
1
解决办法
6970
查看次数

相同的方法调用,LinkedList、Queue 与 List 的不同结果

我已经阅读了LinkedList, queue vs list 中的线程差异,但仍然不理解以下代码行为:

List<Integer> l = new LinkedList<>();
l.add(10);
l.add(12);
l.remove(1); // removes index 1
System.out.println(l); // outputs [10]
    
Queue<Integer> q2 = new LinkedList<>();
q2.add(10);
q2.add(12);
q2.remove(1); // tries to remove object 1
System.out.println(q2); // outputs [10, 12]
Run Code Online (Sandbox Code Playgroud)

我知道,为什么输出不同:

  • 在l调用的情况下remove(1)删除具有索引的元素1
  • 如果q调用remove(1)试图删除一个对象1,但只有整数10和12.

如果我仔细看看接口:

  • Queue没有remove(int)方法,而是remove(Object)从Collection继承了一个方法。
  • List有一个remove(int index)andremove(Object o)方法。

到现在为止还挺好。 …

java queue linked-list list

3
推荐指数
1
解决办法
63
查看次数