<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "> : ( <div><br></div><div>False alarm, the earlier solution breaks multiprocessing. Whats happening here is the child needs to change a variable in the parent process, So I think I am looking at shared memory (maybe). Any suggestions?</div><div><br></div><div>Regards,</div><div>Nav</div><div><br></div><div><br></div><div><br><div><div>On 04-Aug-2010, at 12:41 PM, Navkirat Singh wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Thanks a lot guys !!<div><br></div><div>I solved the problem:</div><div><br></div><div>In the lines:</div><div><br></div><div><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; "><div style="word-wrap: break-word; "><div><div class="h5"><div><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; ">new_process = process(target=newprocess)<br>                       new_process.start()</blockquote></div></blockquote></div></div></div></div></blockquote></div></blockquote></div><div><br></div><div><br></div><div>The target=newprocess is pointing towards a variable, instead of a function. So, appending a () will make it goto that function, thereby changing the global variable : )</div><div><br></div><div>Thanks,</div><div>Nav</div><div><br></div><div><br><div><div>On 04-Aug-2010, at 11:42 AM, Daniel da Silva wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Your problem lies somewhere in the use of the Process class, not with global variables.<br><br>If you replace your "p = ..." and "p.start()" lines with a direct call to self.handle_connection(), your code works as expected. I don't know much about the multiprocessing module, so I can't really comment on what you're doing wrong, but I hope this points you in the right direction.<br>
<br>Sorry I couldn't be of more help,<br><br>Daniel<br><br><br><div class="gmail_quote">On Tue, Aug 3, 2010 at 9:48 PM, Navkirat Singh <span dir="ltr"><<a href="mailto:navkirats@gmail.com">navkirats@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; "><div style="word-wrap: break-word;"><div><div></div><div class="h5"><br><div><div>On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote:</div>
<br><blockquote type="cite">Please post approximate code that actually works and displays the problem. <br><br><div class="gmail_quote">On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh <span dir="ltr"><<a href="mailto:navkirats@gmail.com" target="_blank">navkirats@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin-top: 0pt; margin-right: 0pt; margin-bottom: 0pt; margin-left: 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto; ">Hey guys,<br>
<br>
I am using a multiprocessing program, where the new process is supposed to change a variable in the main class that it branches out from. This is somehow not working, following is an approximate code. Would really appreciate any insight into this matter:<br>


<br>
<br>
var = {}<br>
<br>
class Something():<br>
<br>
        def set_var(self):<br>
                global var<br>
                var = somevalue<br>
<br>
        def get_var(self):<br>
                return var<br>
<br>
        def newprocess(self):<br>
                self.set_var()<br>
<br>
        def do_multiprocessing(self):<br>
                while true:<br>
                        self.get_var()<br>
                        new_process = process(target=newprocess)<br>
                        new_process.start()<br>
<br>
<br>
I am really confused here !<br>
<br>
Any help would be awesome : )<br>
<br>
Regards,<br>
Nav<br>
<font color="#888888"><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>
</blockquote><br></div></div></div><div>This is a working code, streamlined, but it is where the problem is:</div><div><br></div><div><div>from multiprocessing import * </div><div><br></div><div>dicts = 0</div><div>print('global ', dicts)</div>
<div><br></div><div>class WebServer():</div><div><span style="white-space: pre-wrap;">      </span></div><div><span style="white-space: pre-wrap;">       </span>def set_sessionInfo(self):</div><div><span style="white-space: pre-wrap;">             </span>global dicts</div>
<div><span style="white-space: pre-wrap;">                </span>dicts = dicts + 1</div><div><span style="white-space: pre-wrap;">      </span></div><div><span style="white-space: pre-wrap;">       </span>def get_sessionInfo(self):</div><div><span style="white-space: pre-wrap;">             </span>return dicts<span style="white-space: pre-wrap;">  </span></div>
<div><br></div><div><span style="white-space: pre-wrap;">       </span>def handle_connection(self):</div><div><span style="white-space: pre-wrap;">           </span>self.set_sessionInfo()</div><div><span style="white-space: pre-wrap;"> </span></div>
<div><span style="white-space: pre-wrap;">        </span>def serve_forever(self):</div><div><span style="white-space: pre-wrap;">               </span>for x in range(10):</div><div><span style="white-space: pre-wrap;">                    </span>p = Process(target=self.handle_connection)</div>
<div><span style="white-space: pre-wrap;">                        </span>p.start()</div><div><span style="white-space: pre-wrap;">                      </span>print(self.get_sessionInfo())</div><div><span style="white-space: pre-wrap;">                  </span></div><div>ws = WebServer()</div>
<div>ws.serve_forever()</div><div>print(dicts)</div><div><br></div></div><br></div></blockquote></div><br>
</blockquote></div><br></div></div></blockquote></div><br></div></body></html>