質問

についての共有リソースファイルの取扱い間プロセス。こちらは自試験のコード:

from multiprocessing import Process,Lock,freeze_support,Queue
import tempfile
#from cStringIO import StringIO

class File():
    def __init__(self):
        self.temp = tempfile.TemporaryFile()
        #print self.temp

    def read(self):
        print "reading!!!"
        s = "huanghao is a good boy !!"
        print >> self.temp,s
        self.temp.seek(0,0)

        f_content = self.temp.read()
        print f_content

class MyProcess(Process):
    def __init__(self,queue,*args,**kwargs):
        Process.__init__(self,*args,**kwargs)
        self.queue = queue

    def run(self):
        print "ready to get the file object"
        self.queue.get().read()
        print "file object got"
        file.read()

if __name__ == "__main__":
    freeze_support()
    queue = Queue()
    file = File()

    queue.put(file)
    print "file just put"

    p = MyProcess(queue)
    p.start()

その後を取得します KeyError 以下のように:

file just put
ready to get the file object
Process MyProcess-1:
Traceback (most recent call last):
  File "D:\Python26\lib\multiprocessing\process.py", line 231, in _bootstrap
    self.run()
  File "E:\tmp\mpt.py", line 35, in run
    self.queue.get().read()
  File "D:\Python26\lib\multiprocessing\queues.py", line 91, in get
    res = self._recv()
  File "D:\Python26\lib\tempfile.py", line 375, in __getattr__
    file = self.__dict__['file']
KeyError: 'file'

と思いをのせた時の File() オブジェクトにキュー、オブジェクト直列化された、ファイルの操作で子供から高齢者まで扱いできない直列化されたものだと感じました KeyError:

もう聞いてみよう。したい場合は共有オブジェクトファイルを扱うの属性は、どうすればいいですか?

役に立ちましたか?

解決

うれしいオブジェクト(長さだけにとどまるわけにはいかなわcommentl;-)を@マークを繰り返し主張するファイルを扱うだけではできないか"過程とプロセス"--これは、真実に、最近のオペレーティングシステムなど、あえて、Unix(無料BSDの異なるMacOSX,Linuxに含--う~ん、どんなOSの人たちにはこのリスト...?-) -- sendmsg もちろんです("Unixソケット用 SCM_RIGHTS flag).

現在は貴重な multiprocessing はない権利をこの機能(たとえあ黒魔法のプロジェクトを実施するWindows)--開うな誤用でもかまいませんが、結局(有する複数のプロセスアクセスが同じファイルを開く同時にトレースします。の適切な方法を使用するためのプロセスを整備するととは独占的権利を開特定のファイルを開くファイルを扱うプロセスが動低減特典として使用する対応そのものです。ように実施の multiprocessing モジュールされています。

バ@アンディナ問いう仕事はLinuxのみ、地元のプロセスのみ)および姿勢を汚しなの/procファイルシステムのたのかを定義する彼のアプリケーション-レベルのニーズをより大幅にとserialize file オブジェです。最もファイルのパス(またはできてい:path-以下のファイルにもとても珍しいが、実は存在しないWindowsと思う)とすることができればす直列化された経由でくるほど小さいことが明らかになっserialize送そのコンテンツ--などがあります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top