Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.04; 'subject:code': 0.07; 'c/c++': 0.09; 'res': 0.09; 'spawn': 0.09; 'subject:skip:m 10': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'c/c++,': 0.16; 'executable,': 0.16; 'executables': 0.16; 'func():': 0.16; 'reload': 0.16; 'setup(self):': 0.16; 'byte': 0.17; 'instance': 0.17; 'import': 0.21; 'runs': 0.22; 'cc:2**0': 0.23; 'seems': 0.23; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'embedded': 0.27; 'dll': 0.27; 'run': 0.28; 'objects': 0.29; 'skip:& 10': 0.29; 'class': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'function': 0.30; 'code': 0.31; 'running': 0.32; 'safely': 0.33; 'another': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'problems': 0.36; 'skip:p 20': 0.36; 'possible': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'sure': 0.38; 'gives': 0.39; 'system.': 0.39; 'short': 0.39; 'easy': 0.60; 'remove': 0.61; 'different': 0.63; 'obtained': 0.71; 'andrea': 0.84; 'received:209.85.216.184': 0.84 Newsgroups: comp.lang.python Date: Thu, 19 Jul 2012 08:08:49 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.83.145; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.83.145 MIME-Version: 1.0 Subject: Re: reloading code and multiprocessing From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list 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: , Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342710532 news.xs4all.nl 6912 [2001:888:2000:d::a6]:37109 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25629 andrea crotti=E6=96=BC 2012=E5=B9=B47=E6=9C=8819=E6=97=A5=E6=98=9F=E6=9C=9F= =E5=9B=9BUTC+8=E4=B8=8B=E5=8D=886=E6=99=8215=E5=88=8611=E7=A7=92=E5=AF=AB= =E9=81=93=EF=BC=9A > We need to be able to reload code on a live system. This live system > has a daemon process always running but it runs many subprocesses with > multiprocessing, and the subprocesses might have a short life... >=20 > Now I found a way to reload the code successfully, as you can see from > this testcase: >=20 >=20 > def func(): > from . import a > print(a.ret()) >=20 >=20 > class TestMultiProc(unittest.TestCase): > def setUp(self): > open(path.join(cur_dir, 'a.py'), 'w').write(old_a= ) >=20 > def tearDown(self): > remove(path.join(cur_dir, 'a.py')) >=20 > def test_reloading(self): > """Starting a new process gives a different result > """ > p1 =3D Process(target=3Dfunc) > p2 =3D Process(target=3Dfunc) > p1.start() > res =3D p1.join() > open(path.join(cur_dir, 'a.py'), 'w').write(new_a= ) > remove(path.join(cur_dir, 'a.pyc')) >=20 > p2.start() > res =3D p2.join() >=20 >=20 > As long as I import the code in the function and make sure to remove the > "pyc" files everything seems to work.. > Are there any possible problems which I'm not seeing in this approach= or > it's safe? >=20 > Any other better ways otherwise? If a byte code interpreter is embedded in the executable, then the program= =20 can obtain or reload code objects in the run time. In C/C++, unless one can swap some DLL safely or spawn in another process w= ith=20 new executables obtained from other places, or a script interpreter is embe= dded, otherwise it's not easy for an instance in C/C++ to get new methods d= ynamically. or=20