首页 \ 问答 \ 多个进程可以写入同一个文件夹吗?(Can multiple processes write to the same folder?)

多个进程可以写入同一个文件夹吗?(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
更新时间:2022-04-25 16:04

最满意答案

如果你可以将枚举提升到编译时常数,那么它是可能的:

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& ) {
    ...
}

相关问答

更多

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)