Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25617
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <andrea.crotti.0@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '"""': 0.05; 'subject:code': 0.07; 'res': 0.09; 'subject:skip:m 10': 0.09; 'def': 0.10; 'to:name:python-list': 0.15; 'func():': 0.16; 'reload': 0.16; 'setup(self):': 0.16; 'import': 0.21; 'runs': 0.22; 'seems': 0.23; 'message-id:@mail.gmail.com': 0.27; 'class': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'function': 0.30; 'code': 0.31; 'running': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; '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; 'files': 0.38; 'skip:o 20': 0.38; 'sure': 0.38; 'gives': 0.39; 'system.': 0.39; 'to:addr:python.org': 0.39; 'short': 0.39; 'header:Received:5': 0.40; 'remove': 0.61; 'different': 0.63 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=xYdBiDVLyleYGxhOglng+LIinF5PpQ8nob1439zQ3pY=; b=hLw8kzyANm86G69Gs32yeaeHcccNmaAru3+y0ksAVwimBUsW8VmfsPSy7yGRuF/lPo u1EE/6Wltq995v5nzsH45Zd83tCIdUPP87XmbCVYPvkIaCSZZ7SVanwJU1812PhtsUFO v8stNMUZBT9CGoUYmVdUlmMnyICX+dngrg4g5a5dM0XQK85FdZn6Wp1UoBeocs+o5cwo KY5zMrW+Q+AwExhRBdaOGTdIZieCYVlzQHwTsKR9JvSLdZK/lALjmgDCRW3wwyJgg68l skRUqzKETFd+iAWdkFbKwBr2rHvzTrbhCTunUlQ57Oi6P6q0BZPIWUHTBy1wBdJB+M/s bV8g== |
| MIME-Version | 1.0 |
| Date | Thu, 19 Jul 2012 11:15:11 +0100 |
| Subject | reloading code and multiprocessing |
| From | andrea crotti <andrea.crotti.0@gmail.com> |
| To | python-list <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2296.1342692914.4697.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1342692914 news.xs4all.nl 6961 [2001:888:2000:d::a6]:35848 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:25617 |
Show key headers only | View raw
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?
Back to comp.lang.python | Previous | Next — Next 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