Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25629
| 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 | <dihedral88888@googlemail.com> |
| 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 | <mailman.2296.1342692914.4697.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=123.192.83.145; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw |
| References | <mailman.2296.1342692914.4697.python-list@python.org> |
| 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 <dihedral88888@googlemail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list <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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Message-ID | <mailman.2304.1342710532.4697.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
andrea crotti於 2012年7月19日星期四UTC+8下午6時15分11秒寫道: > 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... > > Now I found a way to reload the code successfully, as you can see from > this testcase: > > > def func(): > from . import a > print(a.ret()) > > > class TestMultiProc(unittest.TestCase): > def setUp(self): > open(path.join(cur_dir, 'a.py'), 'w').write(old_a) > > def tearDown(self): > remove(path.join(cur_dir, 'a.py')) > > def test_reloading(self): > """Starting a new process gives a different result > """ > p1 = Process(target=func) > p2 = Process(target=func) > p1.start() > res = p1.join() > open(path.join(cur_dir, 'a.py'), 'w').write(new_a) > remove(path.join(cur_dir, 'a.pyc')) > > p2.start() > res = p2.join() > > > 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? > > Any other better ways otherwise? If a byte code interpreter is embedded in the executable, then the program 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 with new executables obtained from other places, or a script interpreter is embedded, otherwise it's not easy for an instance in C/C++ to get new methods dynamically. or
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
reloading code and multiprocessing andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-19 11:15 +0100 Re: reloading code and multiprocessing 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-19 08:08 -0700 Re: reloading code and multiprocessing 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-19 08:08 -0700
csiph-web