让我们来看看下一个片段 -
@event.listens_for(Pool, "checkout")
def check_connection(dbapi_con, con_record, con_proxy):
cursor = dbapi_con.cursor()
try:
cursor.execute("SELECT 1") # could also be dbapi_con.ping(),
# not sure what is better
except exc.OperationalError, ex:
if ex.args[0] in (2006, # MySQL server has gone away
2013, # Lost connection to MySQL server during query
2055): # Lost connection to MySQL server at '%s', system error: %d
# caught by pool, which will retry with a new connection
raise exc.DisconnectionError()
else:
raise
engine = create_engine('mysql://user:puss123@10.0.51.5/dbname', pool_recycle = 3600,pool_size=10, …Run Code Online (Sandbox Code Playgroud) 我正在使用 celery 来执行异步任务,我想要实现的是在执行任务后获取工作流中每个任务的名称和 id。
exec_workflow = chain(
task1.si(),
task2.si(),
task3.si()
)
result = exec_workflow.apply_async()
tasks = []
for t in result._parents():
tasks.append({"id": t.id, "name": t.name})
Run Code Online (Sandbox Code Playgroud)
但由于某些奇怪的原因,AsyncResult 似乎没有 name 属性。知道什么是适当的方法来做到这一点吗?
另一种方法可能是在执行 apply_async 之前在每个任务上强制使用 id,这将解决我的问题,因为我将能够将 id 与任务名称匹配。但我不确定是否可能。
谢谢。
我目前正试图解决一个棘手/愚蠢的挑战,我已经走到了尽头.
挑战基本上是形成一个单行/ bin/sh兼容命令行,它基本上输出"Hello World"而不直接在命令本身中键入White空格或Tab字符.
例如像 -
echo Hello World
Run Code Online (Sandbox Code Playgroud)
因为我们在命令行中使用了两次空格,所以会无效.
有任何想法吗?