首页 \ 问答 \ gevent + concurrent.futures和SQLAlchemy(gevent + concurrent.futures and SQLAlchemy)

gevent + concurrent.futures和SQLAlchemy(gevent + concurrent.futures and SQLAlchemy)

我正在使用gevent异步工作程序在gunicorn容器内运行和pyramid应用程序,其中一个端点是通过kombu汇集AMQP的长池端点。

如果具有30秒超时的长池从AMQP返回一些数据,我需要在返回之前将其保存到postgres,现在的问题是:

可以在gevent循环中运行的应用程序的上下文中启动concurrent.futures.ThreadPoolExecutor ,并在提交给执行程序的未来内处理SQLAlchemy会话和数据持久性吗?

或者我的思维方式完全错了?

PS DB驱动程序是psycopg2


I'm running and pyramid app inside gunicorn container with gevent async workers, one of endpoints is a long-pool endpoint pooling AMQP via kombu.

If the long pool withing 30s timeout returns some data from AMQP I need to save it to postgres before returning, now the question is:

Is it OK to start concurrent.futures.ThreadPoolExecutor in context on app running in gevent loop, and deal with SQLAlchemy sessions and data persistence inside a future submitted to executor?

Or am I completely wrong in my way of thinking?

PS DB driver is psycopg2


原文:https://stackoverflow.com/questions/37728069
更新时间:2022-05-16 18:05

最满意答案

在这种特殊情况下,您可以使用matchstr() (它返回匹配本身,而不是起始位置),并使匹配在\zs _ssertion 之前的 \zs

matchstr("testingThis", '\ving\zs(.*)')

在一般情况下,有matchlist() ,它返回整个匹配的List以及所有捕获的组。 结果是在第一个捕获组中,因此索引1处的元素:

matchlist("testingThis", '\ving(.*)')[1]

In this particular case, you can use matchstr() (which returns the match itself, not the start position), and let the match start after the before-assertion with \zs:

matchstr("testingThis", '\ving\zs(.*)')

In the general case, there's matchlist(), which returns a List of the entire match plus all captured groups. The result is in the first capture group, so the element at index 1:

matchlist("testingThis", '\ving(.*)')[1]

相关问答

更多
  • 到目前为止,您的代码中似乎存在大量拼写错误。 此外,这看起来像一个问题集问题,所以我将把它作为进一步的练习,以了解更正是什么。 你在正确的轨道上: var pat1 = /^[a-z]+$/i; var pat2 = /^[a-z]+(?: [a-z]+)?$/i; var pat3 = /^\d{10}$/; var pat4 = /^\d{3} \d{2} \d{4}$/; var pat5 = /^\(\d{3}\) \d{3} \d{4}$/; for (var i = 0; i < arr.le ...
  • 在这种特殊情况下,您可以使用matchstr() (它返回匹配本身,而不是起始位置),并使匹配在\zs _ssertion 之前的 \zs : matchstr("testingThis", '\ving\zs(.*)') 在一般情况下,有matchlist() ,它返回整个匹配的List以及所有捕获的组。 结果是在第一个捕获组中,因此索引1处的元素: matchlist("testingThis", '\ving(.*)')[1] In this particular case, you can us ...
  • 正如您在评论中所发现的那样,通常原因是另一个语法组的干扰(在您的情况下,通过不同的插件,Rainbow Parenthesis)。 如果这是相同语法的一部分,您通常可以通过更改嵌套层次结构来修复问题,但是使用外部插件,您可能会运气不好。 问题是Vim只提供两种突出显示机制:syntax (绑定到缓冲区)和:match / matchadd() ,它绑定到窗口。 因此,如果您想要缓冲区的自定义突出显示,则必须使用:syntax和风险干扰文件类型的语法,或者使用matchadd()并且必须使用复杂的matcha ...
  • 不要使用.*? 。 而是使用[^\]]+和[^\)]+ 换一种说法: r'\[([^\]]+)\]\(([^\)]+)\)' Don't use .*?. Instead use [^\]]+ and [^\)]+ In other words: r'\[([^\]]+)\]\(([^\)]+)\)'
  • Pattern.matches匹配整个字符串。 您可以修改模式,也可以使用Matcher.find 。 选项1: Pattern.matches(".*[.!?]", "test.") 选项2: Pattern.compile("[.!?]$").matcher("test.").find() Pattern.matches matches against the entire string. You can either modify your pattern, or use Matcher.find i ...
  • :\@! 只有在没有冒号的情况下才会说匹配,如果我读得正确的话。 我不熟悉这种匹配的ruby语法,所以这可能不太正确。 见:help /\@! 以及周围的主题,了解更多关于外观的信息。 你可以有一个没有\ze的\zs ,它只是意味着匹配的结尾是在正则表达式的末尾。 反之亦然。 \%(\)只是创建一个分组,就像\(\)一样,除了该组不可用作反向引用(就像在:substitute命令中使用的那样)。 :\@! says to match only if there is not a colon, if I re ...
  • 这将发现由空格包围的2个字母单词,或者如果该句子以2个字母单词开始,在这种情况下,它将会被找到。 因此,“He”和“it”都将被发现。 (( .. )|(^.. )) 编辑 - 更深入的解释 搜索2个字母的单词,我们使用。 (点),因此我们有“..”,但是这会找到任何2个字符,所以我们需要用空格包围,所以我们搜索“..”,因此只有2个字符被包围通过空格,这将被发现。 但现在我们有一个新问题。 句子中的前两个字母单词没有空格。 所以它不会被发现。 因此我们添加| (或)去查找相同的表达式,除了这次我们用^来 ...
  • 让你的量词懒惰通过添加一个? + 。 否则,它会从字符串中的开头(到最后)尽可能地贪婪地消费。 var string = "foo bar (10-12) foo (5-10) bar", pattern = /\(.+?\)/g, matches = string.match(pattern); jsFiddle 。 如果你不想在你的比赛中包括括号,通常你会使用积极的向前看和向后看括号。 JavaScript不支持向后看(尽管你可以伪造它们)。 所以,使用... var string = ...
  • 它不会给你两场比赛。 它只是为您提供第一个捕获组的完全匹配。 只需删除外部未转义的括号,第二个“匹配”应该消失: \((?!fe|Fe).+?\) 如果您稍后需要这些括号,但仍然不需要它将生成的捕获子字符串,您还可以使用?:来使用括号不捕获: \((?:(?!fe|Fe).+?)\) 这两个是等价的,但后者略有多余。 此外,如果要匹配某些分隔内容,通常认为使用负字符类而不是不重复重复是一种好习惯: \((?!fe|Fe)[^)]+\) (这应该是等价的) It does not give you tw ...
  • 如果你打印m ,你会看到gregexpr(..., perl = TRUE)为你提供a)你的完整模式的匹配位置和长度,包括前导和右引号以及b)捕获的(.*) 。 不幸的是,当m由regmatches使用时,它使用前者的位置和长度。 我能想到两种解决方案。 通过sub传递你的最终输出: line <- 'VARIABLES = "First [T]" "Second [L]" "Third [1/T]"' m <- gregexpr('"(.*?)"', line, perl = TRUE) z <- reg ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)