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 viakombu
.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
最满意答案
在这种特殊情况下,您可以使用
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]
相关问答
更多-
正则表达式匹配变量(Regex Matching Variables)[2022-09-01]
到目前为止,您的代码中似乎存在大量拼写错误。 此外,这看起来像一个问题集问题,所以我将把它作为进一步的练习,以了解更正是什么。 你在正确的轨道上: 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 ...
-
破译vim正则表达式(deciphering vim regex)[2021-12-19]
:\@! 只有在没有冒号的情况下才会说匹配,如果我读得正确的话。 我不熟悉这种匹配的ruby语法,所以这可能不太正确。 见:help /\@! 以及周围的主题,了解更多关于外观的信息。 你可以有一个没有\ze的\zs ,它只是意味着匹配的结尾是在正则表达式的末尾。 反之亦然。 \%(\)只是创建一个分组,就像\(\)一样,除了该组不可用作反向引用(就像在:substitute命令中使用的那样)。 :\@! says to match only if there is not a colon, if I re ... -
使用正则表达式匹配单词(Matching words using regex)[2022-04-29]
这将发现由空格包围的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 = ...
-
逆正则表达式匹配(Inverse Regex Matching)[2022-11-11]
它不会给你两场比赛。 它只是为您提供第一个捕获组的完全匹配。 只需删除外部未转义的括号,第二个“匹配”应该消失: \((?!fe|Fe).+?\) 如果您稍后需要这些括号,但仍然不需要它将生成的捕获子字符串,您还可以使用?:来使用括号不捕获: \((?:(?!fe|Fe).+?)\) 这两个是等价的,但后者略有多余。 此外,如果要匹配某些分隔内容,通常认为使用负字符类而不是不重复重复是一种好习惯: \((?!fe|Fe)[^)]+\) (这应该是等价的) It does not give you tw ... -
括号内的正则表达式匹配(regex match within parenthesis)[2022-04-27]
如果你打印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 ...