Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'ignored': 0.07; '"__main__":': 0.09; 'decorator': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'subject:How': 0.10; 'def': 0.12; 'thread': 0.14; '[1].': 0.16; 'filename:fname piece:signature': 0.16; 'func': 0.16; 'spurious': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'chris': 0.29; '[1]': 0.29; 'am,': 0.29; 'errors': 0.30; 'idea,': 0.31; 'keyerror:': 0.31; 'omitted': 0.31; 'subject:some': 0.31; 'though.': 0.31; 'could': 0.34; 'something': 0.35; 'really': 0.36; 'should': 0.36; 'wrong': 0.37; 'too': 0.37; 'being': 0.38; 'implement': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'easy': 0.60; 'ian': 0.60; 'manually': 0.60; 'received:173': 0.61; 'soon': 0.63; 'printing,': 0.74; '10:32': 0.84; 'ethan': 0.84; 'furman': 0.84 Date: Mon, 01 Dec 2014 15:19:51 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How about some syntactic sugar for " __name__ == '__main__' "? References: <71b9a111-283f-4006-bc9d-e35782d9888c@googlegroups.com> <5464F958.4070404@stoneleaf.us> In-Reply-To: <5464F958.4070404@stoneleaf.us> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ePpNXabgMbC7MMm6rVv8UojThl9uFknJH" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417475999 news.xs4all.nl 2841 [2001:888:2000:d::a6]:55587 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81787 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --ePpNXabgMbC7MMm6rVv8UojThl9uFknJH Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 11/13/2014 10:32 AM, Ethan Furman wrote: > On 11/12/2014 01:51 PM, Ian Kelly wrote: >> On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor wrote: >>> >>> A decorator is an interesting idea, and should be easy to implement (= only >>> lightly tested): >>> >>> def main(func): >>> if func.__module__ =3D=3D "__main__": >>> func() >>> return func # The return could be omitted to block the function = from >>> being manually called after import. >> >> This calls it at the wrong time, though. [...] >=20 > One decorator that won't call too early is atexit.register(). Well, I've tried this out, and it's only okay. As soon as interesting th= ings start happening, spurious errors about thread IDs start printing, which really messes up the user experience [1]= =2E [1] something like Exception KeyError: KeyError(139924387112272,) in ignored -- ~Ethan~ --ePpNXabgMbC7MMm6rVv8UojThl9uFknJH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJUfPeZAAoJENZ7D1rrH75N8coQAIElerMMREaEzoYxCfF9Weo0 E1w7O9NN4V3UyLzjrCb5TrpHjmzyvncIHa8cqr+I0pVZFFG/a4w9Q8hcE+dMY0AT kPaX5P1yXzRDsbxSVLbcdKHg7RoqCrnKTYQ+pIpneJEIVa9myAB3K9uuYlGa1R1J +F4AriA2fHQ+EJRYRUpWgZh6vXZtprHN7OeNNw8E1C5fN4SiTiwcjGIj+SB15JCu Spx3c2YEstkjBV2RDaSvk+bxTXGa5gKvrxjJY/lI6hYDfpMzkZcVjiQ/ONS0KpLO golKPkY+iEb8ZhTk5Ie7NjlQMJ4UmNbXa47pdydN33U4WQdv/LY/agLYdJlfxmb6 k2PyAiuDEZO8QZUFC9HD2uJQVmGZPGHrmhv116uijg/58KL67RtgR/ITWbh9kYj5 BlxlTTyc5uvFhKAD6xKsxkVjUrw7Reo9fsFnwnqUVGHkMqj3/xBMqNQn82Zr6+e+ a9/KAdmmsdXiU4GNykRGGHCQYAePXJBSCW4+GST2Kcu1c5pXWJcJ1Tq2qf9DEz69 AQgQTl9eM0pG7Gdy398JtW0ZoTwH6yFF5rrxwk8VJUnHbC9KKc47gGApGGTSi7QI lD1JDxrY/oKIRP9EUTlXMKPZvTn4v580A0uoW1mVtEcdjI0jDY6C23UoderZRPej eOAs73zn+FuYiXeM0jrl =OB3D -----END PGP SIGNATURE----- --ePpNXabgMbC7MMm6rVv8UojThl9uFknJH--