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


Groups > comp.lang.python > #51286

embedded python and threading

Newsgroups comp.lang.python
Date 2013-07-25 23:15 -0700
Message-ID <a6710206-8676-48c8-ad66-95139e695503@googlegroups.com> (permalink)
Subject embedded python and threading
From "David M. Cotter" <me@davecotter.com>

Show all headers | View raw


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?

Back to comp.lang.python | Previous | NextNext 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