我有一个批处理脚本,它从几个qsub作业开始,我想在它们全部完成后陷阱.
我不想使用-sync选项,因为我希望它们同时运行.每个作业都有一组不同的命令行参数.
我希望我的脚本等到所有工作完成后再做一些事情.我不想使用睡眠功能,例如检查每30秒后是否生成了某些文件,因为这会消耗资源.
我相信Torque可能有一些选择,但我正在运行SGE.
有关如何实现这一点的任何想法吗?
谢谢Ps我找到了另一个线程 链接
有一个反应
您可以使用wait来停止执行,直到完成所有作业.您甚至可以收集所有退出状态和其他运行统计信息(花费的时间,当时完成的工作数,无论如何),如果您循环等待特定ID.
但我不知道如何在不轮询某些价值的情况下使用它.可以使用bash陷阱,但我如何使用qsub?
我在本网站上已经以各种方式看到了这个问题,但它们都没有完全解决我的问题.
我有一个带有单引号的sql语句,并且在使用它进行数据库查询之前尝试使用推荐的做法.所以声明就像
val2="abc 'dostuff'"
sql="INSERT INTO TABLE_A(COL_A,COL_B) VALUES(%s,'%s')" %(val1, val2)
a_cursor.execute(sql)
Run Code Online (Sandbox Code Playgroud)
但是,当我运行这个时,我得到..
ProgrammingError: (1064,"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dostuff'.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?非常感谢Nupur
我在Linux机器上.我的公司有一个已配置的电子邮件交换服务器.我正在使用Python脚本尝试登录到电子邮件服务器,以便我可以以编程方式发送电子邮件.这是我到目前为止 -
server = smtplib.SMTP('email-0.abc.com', 25)
server.set_debuglevel(1)
server.ehlo_or_helo_if_needed()
server.login('abc/johndoe', 'pwd')
Run Code Online (Sandbox Code Playgroud)
但是,在server.login命令中,我收到错误
raise SMTPException("No suitable authentication method found.")
SMTPException: No suitable authentication method found.
Run Code Online (Sandbox Code Playgroud)
有人知道问题是什么吗?
谢谢
我正在尝试为Python配置一些日志记录.来自 http://docs.python.org/howto/logging.html 建议我们使用YAML配置文件 -
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
loggers:
simpleExample:
level: DEBUG
handlers: [console]
propagate: no
root:
level: DEBUG
handlers: [console]
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我用它作为 -
import logging.config
logging.config.dictConfig('logging.config')
Run Code Online (Sandbox Code Playgroud)
但是,在运行它时,我收到一个错误
Traceback (most recent call last):
File "TestLogger.py", line 62, in <module>
Test5()
File "TestLogger.py", line 55, in Test5
logging.config.dictConfig('logging.dict.2.config')
File "/usr/lib/python2.7/logging/config.py", line 776, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python2.7/logging/config.py", line 380, in __init__
self.config = ConvertingDict(config) …Run Code Online (Sandbox Code Playgroud) 我使用的是Python和mySQL,查询之间存在很长的延迟.结果,我得到一个'MySQL连接已经消失'错误,即wait_timeout被超过.
这已经在例如优雅地处理"MySQL已经消失"中进行了讨论
但这并没有具体回答我的问题.
所以我处理这个问题的方法 - 我已经将所有sql执行语句包装在一个方法中 -
def __execute_sql(self,sql,cursor):
try:
cursor.execute(sql)
except MySQLdb.OperationalError, e:
if e[0] == 2006:
self.logger.do_logging('info','DB', "%s : Restarting db" %(e))
self.start_database()
Run Code Online (Sandbox Code Playgroud)
我在代码中有几个地方调用此查询.问题是,我也有几个游标,所以方法调用看起来像 -
self.__execute_sql(sql,self.cursor_a)
self.__execute_sql(sql,self.cursor_b)
Run Code Online (Sandbox Code Playgroud)
等等
在db启动后,我需要一种方法来优雅地重新执行查询.我可以在if语句中包装调用,然后重新执行它
def __execute_sql(self,sql,cursor):
try:
cursor.execute(sql)
return 1
except MySQLdb.OperationalError, e:
if e[0] == 2006:
self.logger.do_logging('info','DB', "%s : Restarting db" %(e))
self.start_database()
return 0
Run Code Online (Sandbox Code Playgroud)
然后
if (self.__execute_sql(sql,self.cursor_a) == 0):
self.__execute_sql(sql,self.cursor_a)
Run Code Online (Sandbox Code Playgroud)
但这很笨重.有一个更好的方法吗?谢谢!!!
我正在使用Python来解析一个大文件.我想做的是
If condition =True
append to list A
else
append to list B
Run Code Online (Sandbox Code Playgroud)
我想为此使用生成器表达式 - 以节省内存.我正在加入实际的代码.
def is_low_qual(read):
lowqual_bp=(bq for bq in phred_quals(read) if bq < qual_threshold)
if iter_length(lowqual_bp) > num_allowed:
return True
else:
return False
lowqual=(read for read in SeqIO.parse(r_file,"fastq") if is_low_qual(read)==True)
highqual=(read for read in SeqIO.parse(r_file,"fastq") if is_low_qual(read)==False)
SeqIO.write(highqual,flt_out_handle,"fastq")
SeqIO.write(lowqual,junk_out_handle,"fastq")
def iter_length(the_gen):
return sum(1 for i in the_gen)
Run Code Online (Sandbox Code Playgroud) 当我尝试过滤时[1,2,0,3,8],if x < 3: return x我最终得到了[1,2].为什么0不包含在此列表中?
def TestFilter(x):
if x < 3:
return x
a = [1,2,0,3,8]
b = filter(TestFilter, a)
print b
Run Code Online (Sandbox Code Playgroud) 我正在使用 Python 2.7。我有一个 .bz2 文件,我需要弄清楚其组件文件的未压缩文件大小,而无需实际解压缩它。我已经找到了对 gzip 和 tar 文件执行此操作的方法。有人知道 bz2 文件的方法吗?
非常感谢
我正在尝试检查全局文件是否已定义的位置。
import os, sys, logging...
global my_logger
def init():
if my_logger is None:
print 'Logger needs to be initialized'
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此命令时,我收到错误:
NameError: global name 'my_logger' is not defined
Run Code Online (Sandbox Code Playgroud)
有没有办法检查变量是否已声明?在运行检查之前是否必须初始化全局变量?
python ×8
mysql ×2
boolean ×1
compression ×1
email ×1
filter ×1
mysql-python ×1
qsub ×1
timeout ×1