开发者

python multiprocessing status of worker

开发者 https://www.devze.com 2023-03-18 21:25 出处:网络
I have a Python-interface class to a big C++ library, which does some work for me (with big amounts of data). I can gracefully stop the work开发者_StackOverflow中文版er by sending it a signal, i.e. os

I have a Python-interface class to a big C++ library, which does some work for me (with big amounts of data). I can gracefully stop the work开发者_StackOverflow中文版er by sending it a signal, i.e. os.kill( pid,signal.SIGINT ). So, I thought I should be able to run the worker in a p = Process(target=worker.run() ) - which works - then at an arbitrary time interrupt the worker by sending it a signal - which works at well - but:

I cannot get the state of the worker back! There are several functions exported, which should give me information on what the worker was doing, but (obviously after calling p.join()), all these functions return, is the initial values. Why? (The worker actually did his work, which I can see in the created output-file, but I don't get the information there, which I'd want during work...)

Using a Queue or a Manager from multiprocessing doesn't seem to be an option, since the object is not really "pickleable", nor would I want to copy everything, if I just need the state of a specific variable in the worker. (I'm not at all sure that I have a firm grasp on this pickleable concept...)

Thanks in advance for any suggestions!


In multiprocessing, workers run as separate processes. Each process has its own address (memory) space.

This means that if a worker changes a variable, the change won't be visible to the parent, unless you've taken steps to make it visible.

0

精彩评论

暂无评论...
验证码 换一张
取 消