Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"""': 0.05; 'socket': 0.05; 'subject:code': 0.07; 'expected.': 0.09; 'idea?': 0.09; 'port,': 0.09; 'received:mail-lpp01m010-f46.google.com': 0.09; 'subject:skip:m 10': 0.09; 'weeks,': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'anyway': 0.11; 'value.': 0.15; 'again..': 0.16; 'generated,': 0.16; 'reload': 0.16; 'subprocess': 0.16; 'sys.modules': 0.16; 'module': 0.19; 'skip:p 30': 0.20; 'trying': 0.21; 'import': 0.21; 'modifying': 0.22; 'parse': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'cc:no real name:2**0': 0.24; 'idea': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'separate': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'run': 0.28; 'protocol.': 0.29; 'queue': 0.29; 'skip:q 20': 0.29; 'class': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'received:209.85.215.46': 0.30; 'function': 0.30; 'figure': 0.30; 'point': 0.31; 'file': 0.32; 'launch': 0.32; 'skip:s 30': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'fail': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'skip:t 40': 0.37; 'communicate': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'sure': 0.38; 'where': 0.40; 'header:Received:5': 0.40; 'first': 0.61; 'hear': 0.63; 'andrea': 0.84; 'listens': 0.84; 'running,': 0.84; 'glad': 0.86 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Muk1MfcV7y47LmhBYCUxccDRz4fbbtnfJgXiZoOxMEQ=; b=xXRhMOcA0BcxG8ifnpg29QCLLYA677XpJcqNreIOWJUOcodgniKYv8/uPBc7FjVoS9 fqoV9o4MsvDQ9LLOHLzaF7MRIIwoAlH9YRTVVk+zDYczkVfRf0RHYijQHtfHxoVgv5hh lu9vzU3mbE+RHGPWKFCHNF38xcjN2EQzmehXo/wtinhkjGE6qtasx+v5IrMvutIgcaxD wCgp39P5tPXk7kFHM10LmFw5MnnqwxGI5ndSk+FGw7V2+bydT2ZGcJ6re/hiWUcKxmcm n8ZIeKMptdeB169D5rDNzbz9eekaD/qHB3VAHt1sIcwswBUni4No5kLFW4tQPShBcS3f ngJw== MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 27 Jul 2012 12:01:03 +0100 Subject: Re: reloading code and multiprocessing From: andrea crotti To: Chris Angelico Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343386865 news.xs4all.nl 6990 [2001:888:2000:d::a6]:41814 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26140 2012/7/25 andrea crotti : > > I would also like to avoid this in general, but we have many > subprocesses to launch and some of them might take weeks, so we need > to have a process which is always running, because there is never a > point in time where we can just say let's stop everything and start again.. > > Anyway if there are better solutions I'm still glad to hear them, but > I would also like to keep it simple.. > > Another thing which now we need to figure out is how to communicate > with the live process.. For example we might want to submit something > manually, which should pass from the main process. > > The first idea is to have a separate process that opens a socket and > listens for data on a local port, with a defined protocol. > > Then the main process can parse these commands and run them. > Are there easier ways otherwise? So I was trying to do this, removing the module from sys.modules and starting a new process (after modifying the file), but it doesn't work as I expected. The last assertion fails, but how? The pyc file is not generated, the module is actually not in sys.modules, and the function doesn't in the subprocess doesn't fail but still returns the old value. Any idea? old_a = "def ret(): return 0" new_a = "def ret(): return 1" def func_no_import(queue): queue.put(a_glob.ret()) class TestMultiProc(unittest.TestCase): def test_reloading_with_global_import(self): """In this case the import is done before the process are started, so we need to clean sys.modules to make sure we reload everything """ queue = Queue() open(path.join(CUR_DIR, 'old_a.py'), 'w').write(old_a) p1 = Process(target=func_no_import, args=(queue, )) p1.start() p1.join() self.assertEqual(queue.get(), 0) open(path.join(CUR_DIR, 'old_a.py'), 'w').write(new_a) del sys.modules['auto_tester.tests.a_glob'] p2 = Process(target=func_no_import, args=(queue, )) p2.start() p2.join() self.assertEqual(queue.get(), 1)