Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78604

Re: Clearing globals in CPython

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <marco.buttu@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'skip:[ 20': 0.04; 'importing': 0.05; 'interpreter.': 0.07; 'broke': 0.09; 'exit': 0.09; 'restart': 0.09; 'marco': 0.16; 'subject:Clearing': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'module': 0.19; 'working.': 0.19; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; "skip:' 10": 0.31; "d'aprano": 0.31; 'steven': 0.31; 'phone:': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'so,': 0.37; 'easiest': 0.38; 'stopped': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'more': 0.64; 'charset:windows-1252': 0.65; 'header:Reply-To:1': 0.67; 'sharing': 0.69; 'reply-to:no real name:2**0': 0.71; 'received :mail-wi0-x229.google.com': 0.91; 'recover': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:message-id:date:reply-to:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=d7UpxmrOs9maQQIu1O+d0GerlV2U39TmFfurOKXHeac=; b=QQxjxLzElRVKeRuFjEwEbO+e1p8CkqsiOn8s7XjF+1SR1FdYsTKGK2Sgjy1wkH9eWa Z7bIwTt1Q24Icwl809iyTntueRgiTdrSF3Sfbq+3hOpTgyf6MZ799VqpSaknpPAyT0YE rnFxIAhejG7jkwQmRivDcbqSyHw3/FhxI9Fo/qdzs7pfmBCuZtHXNM8EXNIGi2LMmw7o JBbksjZRsJquVls/hzDus6n5EzRoFebEc7e3j61qp28Ia60J9kSB8tk4l7A9NIzm1v3c JoVW4KTphX12GFhhDfQvmEgfq/2vccXL+Y4fCqRNurSjnHKKfFRVuwq6yX4L0RsBz59S VZnQ==
X-Received by 10.194.58.13 with SMTP id m13mr5602735wjq.134.1412181564101; Wed, 01 Oct 2014 09:39:24 -0700 (PDT)
From Marco Buttu <marco.buttu@gmail.com>
X-Google-Original-From Marco Buttu <mbuttu@oa-cagliari.inaf.it>
Date Wed, 01 Oct 2014 18:39:20 +0200
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Clearing globals in CPython
References <542c2527$0$13013$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <542c2527$0$13013$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Thu, 02 Oct 2014 15:46:17 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To mbuttu@oa-cagliari.inaf.it
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14551.1412257578.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412257578 news.xs4all.nl 2975 [2001:888:2000:d::a6]:36994
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 4177
X-Received-Body-CRC 1833371300
Xref csiph.com comp.lang.python:78604

Show key headers only | View raw


On 01/10/2014 18:00, Steven D'Aprano wrote:

> Out of curiosity, I ran:
>
> globals().clear()
>
> in the interactive interpreter. It broke much more than I expected!
> Built-ins were no longer available, and import stopped working.

Interesting... :D

> Obviously the easiest way to recover is to exit the current session and
> restart it, but as a challenge, can we recover from this state?

 >>> [].__class__.__module__ # It is a string...
'__builtin__'

So, I do not have any idea about how to get a module without importing 
something. Thanks for sharing :)

-- 
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbuttu@oa-cagliari.inaf.it

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Clearing globals in CPython Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-02 02:00 +1000
  Re: Clearing globals in CPython Chris Angelico <rosuav@gmail.com> - 2014-10-02 02:14 +1000
  Re: Clearing globals in CPython Chris Kaynor <ckaynor@zindagigames.com> - 2014-10-01 10:08 -0700
  Re: Clearing globals in CPython Peter Otten <__peter__@web.de> - 2014-10-01 19:24 +0200
    Re: Clearing globals in CPython Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-02 18:11 +1000
      Re: Clearing globals in CPython Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-02 09:30 +0100
    Re: Clearing globals in CPython jakubo <jakubo@example.org> - 2014-10-06 09:05 +0000
      Re: Clearing globals in CPython Steven D'Aprano <steve@pearwood.info> - 2014-10-06 09:08 +0000
        Re: Clearing globals in CPython Chris Angelico <rosuav@gmail.com> - 2014-10-06 20:30 +1100
  Re: Clearing globals in CPython Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-01 19:17 +0100
  Re: Clearing globals in CPython Terry Reedy <tjreedy@udel.edu> - 2014-10-01 14:44 -0400
  Re: Clearing globals in CPython Marco Buttu <marco.buttu@gmail.com> - 2014-10-01 18:39 +0200
  Re: Clearing globals in CPython Grant Edwards <invalid@invalid.invalid> - 2014-10-02 14:07 +0000
    Re: Clearing globals in CPython Chris Angelico <rosuav@gmail.com> - 2014-10-03 00:12 +1000
    Re: Clearing globals in CPython Stefan Behnel <stefan_ml@behnel.de> - 2014-10-03 07:26 +0200

csiph-web