简单的问题,但谷歌或Pika开源代码没有帮助.有没有办法查询Pika中的当前队列大小(项目计数器)?
我有一个GAE项目(灵活),由1个默认和2个子服务组成:
foo.appspot.comservice1.foo.appspot.comservice2.foo.appspot.com现在我想使用foo.appspot.com的API代理与验证网关到内部服务service1和service2.我写的代理本身,它工作正常.
我正在努力调整GAE防火墙以禁止传入的世界流量service1,service2因为我想强制API用户发送请求foo.appspot.com.foo应允许流向默认服务.
我似乎可以在防火墙设置中输入IP,但不能输入服务名称.文档说它应该工作,但没有说明如何.
谢谢您的帮助!
以下函数在macOS上的Swift 3中执行一个进程.但是如果我在Ubuntu中运行相同的代码,我会收到错误,这Process是一个未解析的标识符.
如何在Swift 3中为Ubuntu运行进程/任务并获取其输出?
import Foundation
// runs a Shell command with arguments and returns the output or ""
class func shell(_ command: String, args: [String] = []) -> String {
let task = Process()
task.launchPath = command
task.arguments = args
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String? = String(data: data,
encoding: String.Encoding.utf8)
task.waitUntilExit()
if let output = output {
if !output.isEmpty {
// remove whitespaces and newline from start …Run Code Online (Sandbox Code Playgroud) 我需要能够优雅地阻止在Pika ioloop中工作的消费者(工人).工人应该在60秒后停止.当前处理的消息应该完成.
我试图connection.close()在回调函数中放一个但是只停止当前线程而不是完整的ioloop.它给出了一个可怕的错误输出.
请参阅我的代码中的第16行及以下内容:我使用了(关于Pika ioloop的基本示例http://pika.github.com/connecting.html#cps-example:
from pika.adapters import SelectConnection
channel = None
def on_connected(connection):
connection.channel(on_channel_open)
def on_channel_open(new_channel):
global channel
channel = new_channel
channel.queue_declare(queue="test", durable=True, exclusive=False, auto_delete=False, callback=on_queue_declared)
def on_queue_declared(frame):
channel.basic_consume(handle_delivery, queue='test')
def handle_delivery(channel, method, header, body):
print body
# timer stuff which did NOT work
global start_time, timeout, connection
time_diff = time.time()-start_time
if time_diff > timeout:
#raise KeyboardInterrupt
connection.close()
timeout = 60
start_time = time.time()
connection = SelectConnection(parameters, on_connected)
try:
connection.ioloop.start()
except KeyboardInterrupt:
connection.close()
connection.ioloop.start()
Run Code Online (Sandbox Code Playgroud) 我目前正在将框架移植到服务器端Swift,在将字符串写入文件时偶然发现崩溃。在macOS下它正在运行。
源代码
#!/usr/bin/swift
import Foundation
let url = URL(string: "/tmp/foo")!
let line = "foobar"
print("writing to \(url)")
try line.write(to: url, atomically: true, encoding: String.Encoding.utf8)
Run Code Online (Sandbox Code Playgroud)
导致细分错误:
root@bd5d9b821031:/# ./test.swift
writing to <CFURL 0x67b66e0 [0x7ff283886840]>{string = /tmp/foo, encoding = 0, base = (null)}
0 swift 0x000000000333cb08 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x000000000333b2d6 llvm::sys::RunSignalHandlers() + 54
2 swift 0x000000000333d63a
3 libpthread.so.0 0x00007ff28921b330
4 libswiftCore.so 0x00007ff285c3f648 swift_getErrorValue + 8
5 libswiftCore.so 0x00007ff2896462d1 swift_getErrorValue + 60845201
6 swift 0x0000000000c161f4 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 996
7 swift 0x0000000000c197af …Run Code Online (Sandbox Code Playgroud)