Python:从多个进程写入单个文件(ZMQ)(Python: write to single file from multiple processes (ZMQ))
我想从多个进程写入单个文件。 确切地说,我宁愿不使用多处理队列解决方案进行多处理,因为有几个子模块由其他开发人员编写。 但是,对此类子模块的每次写入都与写入
zmq
队列相关联。 有没有办法将zmq
消息重定向到文件? 具体来说,我正在寻找http://www.huyng.com/posts/python-logging-from-multiple-processes/的内容,而不使用logging
模块。I want to write to a single file from multiple processes. To be precise, I would rather not use the Multiple processing Queue solution for multiprocessing as there are several submodules written by other developers. However, each write to the file for such submodules is associated with a write to a
zmq
queue. Is there a way I can redirect thezmq
messages to a file? Specifically I am looking for something along the lines of http://www.huyng.com/posts/python-logging-from-multiple-processes/ without using thelogging
module.
原文:https://stackoverflow.com/questions/18624516
满意答案
您可以将伴随对象与自定义“apply”方法一起使用:
case class MyReturnedModel(reason: String) object MyReturnedModel { def apply(mod: ReturnedModel) = MyReturnedModel(mod.reason.toString) } val data: ReturnedModel = ... // Some instance of ReturnedModel val mr = MyReturnModel(data)
请注意,case类及其伴随对象需要位于同一个文件中才能使用。
You can use a companion object with a custom "apply" method:
case class MyReturnedModel(reason: String) object MyReturnedModel { def apply(mod: ReturnedModel) = MyReturnedModel(mod.reason.toString) } val data: ReturnedModel = ... // Some instance of ReturnedModel val mr = MyReturnModel(data)
Just note that the case class and its companion object need to be in the same file for this to work.
相关问答
更多案例类在Scala中映射(Case class to map in Scala)
Scala:隐式转换案例类对的通用解决方案(Scala: Generic solution to implicitly convert pairs of case classes)
在Scala中,是否有简单的方法将案例类转换为元组?(In Scala, is there an easy way to convert a case class into a tuple?)
Scala案例类和Hash Collision(Scala case classes and Hash Collision)
Scala和案例类(Scala and case classes)
具有行为的Scala案例类(Case classes in Scala with behavior)
是否可以在两个具有不同名称和scala中略有不同字段的案例类之间进行转换(Is it possible to convert between two case class with different name and slightly different field in scala)
Scala案例类背后的内容是什么?(What's behind Scala case classes?)
scala在case类之间转换的最佳方法是什么?(What would be the best way in scala to convert between case classes?)
使用Scala applicative将List [Object]转换为case类(Using Scala applicative to convert List[Object] to case class)
相关文章
更多Solr4.7.2启动时的Index locked for write for core问题分析
storm0.9-single
storm学习之Netty代替ZMQ
Java 流(Stream)、文件(File)和IO
【HDFS】HADOOP DISTRIBUTED FILE SYSTEM
用‘button’跟‘text’组合代替‘file’,选择文件后点‘submit’,‘file’的值被清空
《虚拟机系统与进程的通用平台》(Virtual Machines: Versatile Platforms for Systems and Processes)扫描版[PDF]
PHP 中dirname(_file_)
xxx is not in the sudoers file解决方法
Hadoop 1.2.1 单节点安装(Single Node Setup)步骤
最新问答
更多获取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),本站将尽快处理。谢谢合作!