多个进程可以写入同一个文件夹吗?(Can multiple processes write to the same folder?)
我在Ubuntu机器上运行Python中的几个进程(使用multiprocessing.Process)。 每个进程都写入各种临时文件。 每个进程都写入不同的文件,但所有文件都在同一个文件夹中。 这里有潜在的错误风险吗?
我认为可能存在问题的原因是,AFAIK,Unix中的文件夹只是一个文件。 所以它就像几个进程同时写入同一个文件一样,这可能会导致信息丢失。 这真的是潜在的风险吗? 如果是这样,如何解决?
I run several processes in Python (using multiprocessing.Process) on an Ubuntu machine. Each of the processes writes various temporary files. Each process writes different files, but all files are in the same folder. Is there any potential risk of error here?
The reason I think there might be a problem is that, AFAIK, a folder in Unix is just a file. So it's jsut like several processes writing to the same file at the same time, which might cause a loss of information. Is this really a potential risk here? If so, how to solve it?
原文:https://stackoverflow.com/questions/48191238
满意答案
如果你可以将枚举提升到编译时常数,那么它是可能的:
template <MessageType E, class Data> void Send(Data const& ) { ... }
我们可以创建一个类模板,专门针对枚举所期望的每个枚举:
template <MessageType E> struct expected_type; template <> struct expected_type<MessageType::TypeA> { using type = Foo; }; template <> struct expected_type<MessageType::TypeB> { using type = Bar; }; template <> struct expected_type<MessageType::TypeM> { using type = Foo; }; template <MessageType E> using expected_type_t = typename expected_type<E>::type;
然后我们可以使用它来编写静态断言:
template <MessageType E, class Data> void Send(Data const& ) { static_assert(std::is_same<Data, expected_type_t<E>>{}, "!"); // ... }
或者,可以使用该类模板直接设置
Data
类型:template <MessageType E> void Send(expected_type_t<E> const& ) { ... }
If you can lift the enum to a compile time constant, then it's possible:
template <MessageType E, class Data> void Send(Data const& ) { ... }
We can create a class template, specialized on each enum with what that enum expects:
template <MessageType E> struct expected_type; template <> struct expected_type<MessageType::TypeA> { using type = Foo; }; template <> struct expected_type<MessageType::TypeB> { using type = Bar; }; template <> struct expected_type<MessageType::TypeM> { using type = Foo; }; template <MessageType E> using expected_type_t = typename expected_type<E>::type;
And then we can use that to just write that static assert:
template <MessageType E, class Data> void Send(Data const& ) { static_assert(std::is_same<Data, expected_type_t<E>>{}, "!"); // ... }
Alternatively, could use that class template to set the
Data
type directly:template <MessageType E> void Send(expected_type_t<E> const& ) { ... }
相关问答
更多当模板参数相同时,C ++优化类模板函数(C++ optimise class template function when template parameters identical)
具有更多参数的模板(Template with more parameters)
在模板函数参数之间强制实现所需的关系(Enforcing desired relationship between template function parameters)
变量模板作为std :: function的参数(Variadic template as parameters to std::function)
指定一些模板参数(Specifying some template parameters)
模板模板参数和默认参数(Template template parameters and default arguments)
基于运行时值调用不同的模板函数特化(Calling different template function specialisations based on a run-time value)
功能模板采用模板非类型模板参数(Function template taking a template non-type template parameter)
函数与模板中的参数。(Function with arguments in a template. Django)
使用模板参数作为函数参数(Using template parameters as function parameters)
相关文章
更多Solr4.7.2启动时的Index locked for write for core问题分析
《虚拟机系统与进程的通用平台》(Virtual Machines: Versatile Platforms for Systems and Processes)扫描版[PDF]
HDFS patch前后Ganglia看到running processes变化的分析
在java中如何获取文件夹占用空间的大小?(注意这里不是问文件夹大小)
Solr4:Tomcat7与Solr之多核配置(Multiple Cores)
response.getWriter.write()方法和response.getWriter.println()方法区别
删除暴风文件夹内的stormliv.exe
solr 做索引时报 Lock obtain timed out: SingleInstanceLock: write.lock
Hadoop Core 学习笔记(一) SequenceFile文件写入和读取Writable数据
Hadoop Core 学习笔记(二) lzo文件的写入和读取
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!