我是C#的新手,想知道C#中是否存在类似私有继承的东西(比如在C++中)?
我的问题如下:我想实现一个队列(将其命名为SpecialQueue),并进行以下更改:
在c ++中,我会从队列中私有ihnerit,只暴露我想要的方法,并根据我的意愿改变其他方法.但不幸的是,队列中的所有方法都没有"覆盖"修饰符,我不知道如何在C#中实现它.
有帮助吗?
问候,丹
我需要知道何时关闭队列并且不会有更多项目因此我可以结束迭代.
我通过在队列中放置一个标记来做到这一点:
from Queue import Queue
class IterableQueue(Queue):
_sentinel = object()
def __iter__(self):
return self
def close(self):
self.put(self._sentinel)
def next(self):
item = self.get()
if item is self._sentinel:
raise StopIteration
else:
return item
Run Code Online (Sandbox Code Playgroud)
鉴于这是队列的一个非常常见的用途,是不是有任何内置实现?
两个并发后台任务需要修补两个需要在dispatch_group_notify块中合并的独立阵列.问题在于,超出了第一个块但超出了dispatch_group_notify,而没有等待执行第二个后台任务.它们之间唯一不同的是,第一个进行本地搜索,第二个远程调用Web服务.任何线索为什么第二个跳过?
编辑:我也尝试使用dispatch_barrier_async 在/sf/answers/1370640911/中提到的方法,但仍然相同.
dispatch_group_t taskGroup = dispatch_group_create();
dispatch_queue_t mainQueue = dispatch_get_main_queue();
__block NSArray *localAddresses;
__block NSArray *remoteAddresses;
//Get local array in the background
dispatch_group_async(taskGroup, mainQueue, ^{
//localAddresses is set
});
//get remote array from server
dispatch_group_async(taskGroup, mainQueue, ^{
[[MDAddressManager instance] searchForPlacesContainingText:query
location:alocation
completion:^(NSArray* addresses, MDError *error){
//remoteAddresses is set
});
//Merge two arrays
dispatch_group_notify(taskGroup, mainQueue, ^{
//remoteAddresses and local addresses are merged
});
Run Code Online (Sandbox Code Playgroud)
而远程搜索方法看起来像这样
- (void)searchForPlacesContainingText:(NSString *)searchText
location:(CLLocation *)alocation
completion:(MDAddressManagerBlock)completionBlock
{
NSDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters …Run Code Online (Sandbox Code Playgroud) queue asynchronous grand-central-dispatch ios objective-c-blocks
我已经在 Windows Server 2012 64 位上安装了RabbitMQ。
我测试了发布和消耗大量数据的部分一切都很好,我面临的唯一问题是队列中的消息在 RabbitMQServer 重启后丢失。
我正在使用 RabbitMQ 的 VB.Net SDK。
我将"Durable"Queue Declare 的属性设置为 true,DeliveryMode BasicQueueProperties to "2"并使消息持久化。但是在我的服务器重启后消息仍然丢失。
我怎样才能克服这个问题?
我看到的所有内容都是关于列表的,但这是关于events = queue.queue()
哪个队列包含我想要提取的对象,但是我将如何从该队列中获取最后 N 个元素?
所以在 laravel 中我有一个函数,可以发布一些内容并将作业推送到队列中,并从函数(而不是队列)返回一些数据。
现在我认为 Laravel 队列应该是某种异步函数,可以确保您的代码保持快速,即使有大量数据需要处理,因此您将其放入作业中。但我注意到我的代码仍然需要等到作业完成才能将数据返回给用户。这是调用两次的脚本的日志,但一次在作业中几乎没有数据,而另一次则有很多数据:
[2016-09-08 13:26:50] production.INFO: New alert with Image
[2016-09-08 13:26:50] production.INFO: Push is send.
[2016-09-08 13:26:50] production.INFO: Alert data is send back.
[2016-09-08 13:26:50] production.INFO: New image is valid
[2016-09-08 13:26:50] production.INFO: Move file for upload
[2016-09-08 13:26:50] production.INFO: Made it to upload
[2016-09-08 13:28:50] production.INFO: New alert with Image
[2016-09-08 13:31:19] production.INFO: Push is send.
[2016-09-08 13:31:19] production.INFO: Alert data is send back.
[2016-09-08 13:31:20] production.INFO: New image is valid
[2016-09-08 13:31:20] production.INFO: Move …Run Code Online (Sandbox Code Playgroud) 我有一个关于 pythonasyncio模块中的事件循环如何管理未完成任务的问题。考虑以下代码:
import asyncio
@asyncio.coroutine
def a():
for i in range(0, 3):
print('a.' + str(i))
yield
@asyncio.coroutine
def b():
for i in range(0, 3):
print('b.' + str(i))
yield
@asyncio.coroutine
def c():
for i in range(0, 3):
print('c.' + str(i))
yield
tasks = [
asyncio.Task(a()),
asyncio.Task(b()),
asyncio.Task(c()),
]
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait([t1, t2, t3]))
Run Code Online (Sandbox Code Playgroud)
运行这将打印:
a.0
b.0
c.0
a.1
b.1
c.1
a.2
b.2
c.2
Run Code Online (Sandbox Code Playgroud)
请注意,它总是打印出 'a' 然后是 'b' 然后是 'c'。我猜无论每个协程经过多少次迭代,它都将始终按该顺序打印。所以你永远不会看到类似的东西
b.100
c.100
a.100
Run Code Online (Sandbox Code Playgroud)
来自 node.js 背景,这告诉我这里的事件循环在内部维护一个队列,它用来决定接下来运行哪个任务。它最初放在a()队列的前面,然后是b() …
我的 python redis 队列中有一个嵌套的作业结构。首先执行 rncopy 作业。完成后,接下来是 3 个相关的注册作业。当所有这 3 个作业的计算完成后,我想触发一个作业向我的前端发送 websocket 通知。
我目前的尝试:
rncopy = redisqueue.enqueue(raw_nifti_copymachine, patientid, imagepath, timeout=6000)
t1c_reg = redisqueue.enqueue(modality_registrator, patientid, "t1c", timeout=6000, depends_on=rncopy)
t2_reg = redisqueue.enqueue(modality_registrator, patientid, "t2", timeout=6000, depends_on=rncopy)
fla_reg = redisqueue.enqueue(modality_registrator, patientid, "fla", timeout=6000, depends_on=rncopy)
notify = redisqueue.enqueue(print, patient_finished, patientid, timeout=6000, depends_on=(t1c_reg, t2_reg, fla_reg))
Run Code Online (Sandbox Code Playgroud)
不幸的是,似乎多作业依赖功能从未合并到主版本中。我看到目前 git 上有两个拉取请求。有我可以使用的解决方法吗?
很抱歉未能提供可重现的示例。
我已经在互联网上搜索了一段时间,但似乎找不到这方面的答案。
我打算使用 stl::queue 进行一些模拟。我想知道是否可以使用 stl::queue 创建循环队列?据我所知,stl::queue是线性的,默认情况下不是循环的?
如果可能的话,有人有任何实现参考可供我参考吗?
谢谢。
queue ×10
python ×4
asynchronous ×2
laravel ×2
php ×2
c# ×1
c++ ×1
event-loop ×1
inheritance ×1
ios ×1
iteration ×1
laravel-5 ×1
python-3.x ×1
python-rq ×1
rabbitmq ×1
redis ×1
restart ×1
stl ×1
vb.net ×1