我正在通过Linux上的Python子进程模块运行Perl脚本.使用变量输入多次调用运行脚本的函数.
def script_runner(variable_input):
out_file = open('out_' + variable_input, 'wt')
error_file = open('error_' + variable_input, 'wt')
process = subprocess.Popen(['perl', 'script', 'options'], shell=False,
stdout=out_file, stderr=error_file)
Run Code Online (Sandbox Code Playgroud)
但是,如果我运行此函数,例如两次,则第二个进程启动时第一个进程的执行将停止.我可以通过添加来获得我想要的行为
process.wait()
Run Code Online (Sandbox Code Playgroud)
在调用脚本之后,所以我并没有真正陷入困境.但是,我想找出为什么我不能使用子进程多次运行脚本,并让脚本并行进行这些计算,而不必等待它在每次运行之间完成.
UPDATE
罪魁祸首并不那么令人兴奋:perl脚本使用了为每次执行重写的公共文件.
但是,我从中学到的教训是,垃圾收集器在开始运行后不会删除该进程,因为一旦我将其整理出来,这对我的脚本没有任何影响.
在了解了shared变量目前没有受到内存障碍保护的困难之后,我现在遇到了另一个问题.要么我做错了,要么dmd中现有的编译器优化可以通过重新排序shared变量读取来破坏多线程代码.
例如,当我使用dmd -O(完全优化)编译可执行文件时,编译器很乐意优化o此代码中的局部变量(其中cas是比较和交换函数core.atomic)
shared uint cnt;
void atomicInc ( ) { uint o; do { o = cnt; } while ( !cas( &cnt, o, o + 1 ) );}
Run Code Online (Sandbox Code Playgroud)
这样的事情(参见下面的拆卸):
shared uint cnt;
void atomicInc ( ) { while ( !cas( &cnt, cnt, cnt + 1 ) ) { } }
Run Code Online (Sandbox Code Playgroud)
在"优化"代码cnt中从内存中读取两次,从而运行另一个线程cnt之间已经修改的风险.优化基本上破坏了比较和交换算法.
这是一个错误,还是有正确的方法来达到预期的效果?到目前为止,我发现的唯一解决方法是使用汇编程序实现代码.
完整的测试代码和其他详细信息
为了完整性,这里有一个完整的测试代码,可以显示这两个问题(没有内存障碍和优化问题).它在dmd 2.049和dmd 2.050的三台不同的Windows机器上产生以下输出(假设Dekker的算法没有死锁,可能会发生这种情况):
dmd -O -run optbug.d
CAS : …Run Code Online (Sandbox Code Playgroud) 我有一个文件包含这个:
(Float,Float,Float)"sometext"
(Float,Float,Float)"sometext"
(Float,Float,Float)"sometext"
...
...
Run Code Online (Sandbox Code Playgroud)
我希望我的程序从文件中读取一行,将(Float,Float,Float)放入tripple并将"sometext"放入一个String中,并将所有内容放在一个新的数据类型下,这样整个事情看起来就像这样:
SomeDataType(Float,Float,Float)"sometext"
我到目前为止得到了这个:
readFromDisc filePath = do
fileHandle <- openFile "/tmp/lala.txt" ReadMode
contents <- hGetContents fileHandle
putStrLn $ readOneLine contents
Run Code Online (Sandbox Code Playgroud)
如果文件包含:
(5.0,6.0,7.0)"faraway"
(8.0,9.0,0.0)"holdon"
Run Code Online (Sandbox Code Playgroud)
我明白了:
"(5.0,6.0,7.0)\"faraway\""
Run Code Online (Sandbox Code Playgroud)
现在,因为我把它作为一个字符串,我正在考虑使用
breakInput input = break (=='"') input
Run Code Online (Sandbox Code Playgroud)
要得到这个:
("(5.0,6.0,7.0)","\"faraway\"")
Run Code Online (Sandbox Code Playgroud)
这是一对字符串,我打算使用一些东西来解析tripple和文本,但所有这些都感觉不对.
有一个更好的方法吗?
在UDP套接字上使用默认(阻塞)行为时,在这种情况下会调用sendto()块吗?我主要对Linux行为感兴趣.
对于TCP我明白,如果发送窗口已满,拥塞控制会使send()调用阻塞,但UDP呢?它有时会阻塞,还是让数据包在较低层被丢弃?
我有3个版本的Android应用程序.一个免费的广告,一个付费和一个品牌与公司CI.
所以它们之间的区别很小.
管理此应用程序的多个版本的最佳做法是什么?
if (editionA) { ... }我有一个文档管理系统,其中文档可以有多个版本.保存每个版本,用户可以查看版本历史记录.
我想知道的是:我应该使用什么数据类型的版本号?十进制,浮点数还是双倍?我正在使用.NET和C#.
版本号从0.1开始,每个发布的主要版本将四舍五入到下一个整数.即0.4去1.0和1.3进行到2.0等
当版本号达到0.9并且添加了次要版本时,我希望当我添加它时,该数字将变为0.10而不是1.0.这是最大的问题.
任何建议表示赞赏.
谢谢.
我有一些看起来像这样的链接:
<a href="#" class="somelink rotate-90"> ... </a>
Run Code Online (Sandbox Code Playgroud)
如何将函数绑定到具有以" rotate-" 开头的类的所有元素?
我在IIS6中有一个.net Web应用程序托管,Windows身份验证和匿名访问被禁用.Web应用程序正在连接到同一域中但位于不同计算机上的SQL Server.
我希望IIS工作进程帐户I_USR _...被授予访问SQL Server的权限.
这会有用吗?
(是否有一对一的信任?或者我应该做出一些额外的努力来使信任工作?)
(编辑)在这个页面上我读到:
IUSR_必须在域中,并且可以正确访问SQL Server; 或者,您必须禁用站点/应用程序上的匿名访问 - 这将允许IIS将用户的凭据传递给SQL Server.不做这两件事都会导致错误.
我在这个函数中面临一些问题,我遇到了空值并获得了空指针异常.sqlDate并且sqlTime为空.
private void setCalendarComboDetails(Map tenantConnInfo, HttpSession session, HttpServletRequest request) {
logger.info("Enter setCalendarComboDetails");
Appointment appointmentInfo = new Appointment();
Date sqlDate;
Time sqlTime;
try {
CompanyDbImpl companyImpl = new CompanyDbImpl(tenantConnInfo);
PatientDbImpl patientImpl = new PatientDbImpl(tenantConnInfo);
DoctorDbImpl doctorImpl = new DoctorDbImpl(tenantConnInfo);
CalendarDbImpl calendarImpl = new CalendarDbImpl(tenantConnInfo);
ConfigurationDbImpl configurationImpl = new ConfigurationDbImpl(tenantConnInfo);
session.setAttribute("isvalid",true);
session.removeAttribute("appointmentInfo");
// session.removeAttribute("index");
List<CompanyBranchDetails> branchDetailsList = companyImpl.getCompanyNBranchList();
session.setAttribute("companyBranchList", branchDetailsList);
List<PatientInfo> patientList = patientImpl.getPatientInfoList();
session.setAttribute("patientInfoList", patientList);
String whereClause = " dbd.branch_id=" + branchDetailsList.get(0).getBranchId();
List<DoctorBranchDetails> doctorBranchDetailsList = doctorImpl.getDoctorBranchDetailsListByWhereClause(whereClause);
System.out.println("doctor …Run Code Online (Sandbox Code Playgroud)