Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 700049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:27:15+00:00 2026-05-14T03:27:15+00:00

I first ran into this when trying to determine the relative performance of two

  • 0

I first ran into this when trying to determine the relative performance of two generators:

t = timeit.repeat('g.get()', setup='g = my_generator()')

So I dug into the timeit module and found that the setup and statement are evaluated with their own private, initially empty namespaces so naturally the binding of g never becomes accessible to the g.get() statement. The obvious solution is to wrap them into a class, thus adding to the global namespace.

I bumped into this again when attempting, in another project, to use the multiprocessing module to divide a task among workers. I even bundled everything nicely into a class but unfortunately the call

pool.apply_async(runmc, arg) 

fails with a PicklingError because buried inside the work object that runmc instantiates is (effectively) an assignment:

self.predicate = lambda x, y: x > y

so the whole object can’t be (understandably) pickled and whereas:

def foo(x, y): 
    return x > y
pickle.dumps(foo)

is fine, the sequence

bar = lambda x, y: x > y

yields True from callable(bar) and from type(bar), but it Can't pickle <function <lambda> at 0xb759b764>: it's not found as __main__.<lambda>.

I’ve given only code fragments because I can easily fix these cases by merely pulling them out into module or object level defs. The bug here appears to be in my understanding of the semantics of namespace use in general. If the nature of the language requires that I create more def statements I’ll happily do so; I fear that I’m missing an essential concept though. Why is there such a strong reliance on the global namespace? Or, what am I failing to understand?

Namespaces are one honking great idea — let’s do more of those!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:27:15+00:00Added an answer on May 14, 2026 at 3:27 am

    The pickle protocol(s) would have a serious problem picking classes and functions in the most general case; by pickling them “by name” instead, it makes the difficulty go away, but nds up requiring that they be bound to (and recoverable by) names that are top-level in a module (which, since a module is its own namespace, doesn’t conflict with “namespaces are one honking great idea”, after all;-).

    As for your timeit problem, I don’t undestand what you mean wrt “the global namespace” – for example:

    >>> timeit.repeat('g.get(23)', 'g = {}')
    [0.29134988784790039, 0.27160286903381348, 0.27237796783447266]
    

    the namespace where g is bound leaves the binding fully accessible by the statement being repeated. If what you’re binding to g is a generator, maybe your problem is that generators don’t have .get() methods and perhaps you meant .next()?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a website for myself and just ran into this issue:
Was trying out some code with the EF code first method and ran into
Totally revising this question, since I fixed the first issue but have ran into
I'm new to VBA and Access in general and ran into this problem whilst
I was trying to do a regex for someone else when I ran into
I ran into the problem that two drives connected at nearly the same time
I ran into an issue trying to update a foreign key field: record.ForeignId =
I am writing my first MSBuild script and ran into a problem. I have
I'm trying to use scalaz validation in our project and have ran into a
OK, I ran into this today, when the TI TMS470 C++ compiler refused to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.