Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38349
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <stephane@wirtel.be> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'fixes': 0.05; 'seemed': 0.07; 'python': 0.09; 'fixed,': 0.09; 'fork': 0.09; 'happens.': 0.09; 'cc:addr:python-list': 0.10; 'hint?': 0.16; 'illustrates': 0.16; 'received:212.68.199': 0.16; 'received:212.68.199.148': 0.16; 'received:brutele.be': 0.16; 'received:mirapoint3.brutele.be': 0.16; 'everyone,': 0.17; 'import': 0.21; 'cc:2**0': 0.23; 'random': 0.24; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'thanks!': 0.26; 'behaviour': 0.29; 'url:mailman': 0.29; 'this.': 0.29; "i'm": 0.29; 'related': 0.30; 'that.': 0.30; 'expect': 0.31; 'code': 0.31; 'url:python': 0.32; 'anybody': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'problem': 0.33; 'program,': 0.34; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'easily': 0.39; 'url:mail': 0.40; 'content- disposition:inline': 0.60; 'url:be': 0.65; 'today': 0.67; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'received:109': 0.74 |
| Date | Thu, 7 Feb 2013 14:29:33 +0100 |
| From | Stephane Wirtel <stephane@wirtel.be> |
| To | Julien Le Goff <julien.legoff@gmail.com> |
| Subject | Re: Random and fork |
| References | <9efb072f-b671-45da-bc4e-ef224b2ffe76@googlegroups.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Disposition | inline |
| Content-Transfer-Encoding | 8bit |
| In-Reply-To | <9efb072f-b671-45da-bc4e-ef224b2ffe76@googlegroups.com> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-Junkmail-Status | score=10/50, host=mirapoint3.brutele.be |
| X-Junkmail-Signature-Raw | score=unknown, refid=str=0001.0A0B0201.5113AC3E.005D,ss=1,fgs=0, ip=0.0.0.0, so=2011-11-01 07:33:11, dmn=2009-09-10 00:05:08, mode=single engine |
| X-Junkmail-IWF | false |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | stephane@wirtel.be |
| 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.1448.1360243968.2939.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360243968 news.xs4all.nl 6940 [2001:888:2000:d::a6]:43723 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38349 |
Show key headers only | View raw
* Julien Le Goff <julien.legoff@gmail.com> [2013-02-06 08:28:24 -0800]: > Hi everyone, > > Today I came accross a behaviour I did not expect in python (I am using 2.7). In my program, random.random() always seemed to return the same number; it turned out to be related to the fact that I was using os.fork. > > See below a small program that illustrates this. It is easily fixed, but I'm interested in knowing why this happens. Can anybody give me a hint? Thanks! > > import random > import os > > for i in xrange(10): > pid = os.fork() > if pid == 0: > # uncommenting this fixes the problem > # random.seed(os.getpid()) > print random.random() > os._exit(0) > > os.wait() > -- > http://mail.python.org/mailman/listinfo/python-list If you look at the code of gunicorn, you can see than there is a random.seed() just after the fork syscall. Try with that. Regards, -- Stéphane Wirtel - http://wirtel.be - @matrixise
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Random and fork Julien Le Goff <julien.legoff@gmail.com> - 2013-02-06 08:28 -0800
Re: Random and fork Peter Otten <__peter__@web.de> - 2013-02-06 17:47 +0100
Re: Random and fork Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2013-02-06 17:49 +0100
Re: Random and fork Julien Le Goff <julien.legoff@gmail.com> - 2013-02-07 01:41 -0800
Re: Random and fork Stephane Wirtel <stephane@wirtel.be> - 2013-02-07 14:29 +0100
csiph-web