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


Groups > comp.lang.python > #51291

Re: embedded python and threading

From Stefan Behnel <stefan_ml@behnel.de>
Subject Re: embedded python and threading
Date 2013-07-26 11:29 +0200
References <a6710206-8676-48c8-ad66-95139e695503@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.5138.1374831002.3114.python-list@python.org> (permalink)

Show all headers | View raw


David M. Cotter, 26.07.2013 08:15:
> in my app i initialize python on the main thread, then immediately call PyEval_SaveThread() because i do no further python stuff on the main thread.
> 
> then, for each script i want to run, i use boost::threads to create a new thread, then on that thread i "ensure" the GIL, do my stuff, then release it.
> 
> so, to test concurrency, on my first background thread, i do an infinite loop that just logs "i'm alive", then calls sleep(0.25)
> 
> so that thread continues to run forever (with it's GIL ensured)
> 
> according to the doc: "In order to emulate concurrency of execution, the interpreter regularly tries to switch threads"
> 
> so i figure i can run another thread that does a single print statement:
> 
>> ensure gil
>> print my thing
>> release gil
> 
> and this DOES run.  however, after releasing it's gil, i guess the interpeter gets back to the first back thread, but then has this error immediately:
> 
>     9: Traceback (most recent call last):
>     9:   File "<string>", line 70, in ?
>     9:   File "<string>", line 55, in main
>     9: AttributeError: 'builtin_function_or_method' object has no attribute 'sleep'
> 
> suddenly the sleep module has been unloaded?? huh?  i thought the thread state had been preserved?

You didn't show your code, but as a wild guess, maybe you did

    from time import time

instead of

    import time

somewhere? If not, please provide the exact example code that you are running.

Stefan

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


Thread

embedded python and threading "David M. Cotter" <me@davecotter.com> - 2013-07-25 23:15 -0700
  Re: embedded python and threading Stefan Behnel <stefan_ml@behnel.de> - 2013-07-26 11:29 +0200
    Re: embedded python and threading "David M. Cotter" <me@davecotter.com> - 2013-07-26 08:57 -0700
      Re: embedded python and threading David Robinow <drobinow@gmail.com> - 2013-07-26 12:14 -0400
      Re: embedded python and threading John Gordon <gordon@panix.com> - 2013-07-26 16:34 +0000
        Re: embedded python and threading "David M. Cotter" <me@davecotter.com> - 2013-07-26 10:25 -0700
          Re: embedded python and threading "David M. Cotter" <me@davecotter.com> - 2013-07-26 10:28 -0700
            Re: embedded python and threading Stefan Behnel <stefan_ml@behnel.de> - 2013-07-26 20:38 +0200

csiph-web