threading support in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lawrence Oluyede

    #31
    Re: threading support in python

    Sandra-24 <sandravandale@ yahoo.comwrote:
    Oh I'm aware of that, but it's not what I'm looking for. Mod_mono just
    lets you run ASP.NET on Apache. I'd much rather use Python :) Now if
    there was a way to run IronPython on Apache I'd be interested.
    Take a look here:

    2049.html
    and this thread:




    --
    Lawrence - http://www.oluyede.org/blog
    "Nothing is more dangerous than an idea
    if it's the only one you have" - E. A. Chartier

    Comment

    • Lawrence Oluyede

      #32
      Re: threading support in python

      Lawrence Oluyede <rhymes@myself. comwrote:
      Also this: http://www.codeproject.com/useritems/ipaspnet.asp

      Google is you friend! :-)

      --
      Lawrence - http://www.oluyede.org/blog
      "Nothing is more dangerous than an idea
      if it's the only one you have" - E. A. Chartier

      Comment

      • skip@pobox.com

        #33
        Re: threading support in python


        AndreThis seems to be an important issue and fit for discussion in the
        Andrecontext of Py3k. What is Guido's opinion?

        Dunno. I've never tried channeling Guido before. You'd have to ask him.
        Well, maybe Tim Peters will know. He channels Guido on a fairly regular
        basis.

        Skip

        Comment

        • Sandra-24

          #34
          Re: threading support in python

          sjdevnull@yahoo .com wrote:
          You can do the same on Windows if you use CreateProcessEx to create the
          new processes and pass a NULL SectionHandle. I don't think this helps
          in your case, but I was correcting your impression that "you'd have to
          physically double the computer's memory for a dual core, or quadruple
          it for a quadcore". That's just not even near true.
          Sorry, my bad. What I meant to say is that for my application I would
          have to increase the memory linearly with the number of cores. I have
          about 100mb of memory that could be shared between processes, but
          everything else would really need to be duplicated.
          As I said, Apache used to run on Windows with multiple processes; using
          a version that supports that is one option. There are good reasons not
          to do that, though, so you could be stuck with threads.
          I'm not sure it has done that since the 1.3 releases. mod_python will
          work for that, but involves going way back in it's release history as
          well. I really don't feel comfortable with that, and I don't doubt I'd
          give up a lot of things I'd miss.
          Having memory protection is superior to not having it--OS designers
          spent years implementing it, why would you toss out a fair chunk of it?
          Being explicit about what you're sharing is generally better than not.
          Actually, I agree. If shared memory will prove easier, then why not use
          it, if the application lends itself to that.
          But as I said, threads are a better solution if you're sharing the vast
          majority of your memory and have complex data structures to share.
          When you're starting a new project, really think about whether they're
          worth the considerable tradeoffs, though, and consider the merits of a
          multiprocess solution.
          There are merits, the GIL being one of those. I believe I can fairly
          easily rework things into a multi-process environment by duplicating
          memory. Over time I can make the memory usage more efficient by sharing
          some data structures out, but that may not even be necessary. The
          biggest problem is learning my way around Linux servers. I don't think
          I'll choose that option initially, but I may work on it as a project in
          the future. It's about time I got more familiar with Linux anyway.
          It's almost certainly not worth rewriting a large established
          codebase.
          Lazy me is in perfect agreement.
          I disagree with this, though. The benefits of deterministic GC are
          huge and I'd like to see ref-counting semantics as part of the language
          definition. That's a debate I just had in another thread, though, and
          don't want to repeat.
          I just took it for granted that a GC like Java and .NET use is better.
          I'll dig up that thread and have a look at it.
          I didn't say that. It can be a big hit or it can be unnoticeable. It
          depends on your application. You have to benchmark to know for sure.
          >
          But if you're trying to make a guess: if you're doing a lot of heavy
          lifting in native modules then the GIL may be released during those
          calls, and you might get good multithreading performance. If you're
          doing lots of I/O requests the GIL is generally released during those
          and things will be fine. If you're doing lots of heavy crunching in
          Python, the GIL is probably held and can be a big performance issue.
          I don't do a lot of work in native modules, other than the standard
          library things I use, which doesn't count as heavy lifting. However I
          do a fair amount of database calls, and either the GIL is released by
          MySQLdb, or I'll contribute a patch so that it is. At any rate, I will
          measure, and I suspect the GIL will not be an issue.

          -Sandra

          Comment

          • Paul Rubin

            #35
            Re: threading support in python

            skip@pobox.com writes:
            It was removed at one point in the dim, dark past (circa Python 1.4) on an
            experimental basis. Aside from the huge amount of work, it resulted in
            significantly lower performance for single-threaded apps (that is, the
            common case).
            That's probably because they had to put locking and unlocking around
            every access to a reference count. A real GC might have fixed that.

            Comment

            • Paul Rubin

              #36
              Re: threading support in python

              "sjdevnull@yaho o.com" <sjdevnull@yaho o.comwrites:
              I think it's even worse. The standard Python library offers
              shared memory, but not cross-process locks.
              >
              File locks are supported by the standard library (at least on Unix,
              I've not tried on Windows). They work cross-process and are a normal
              method of interprocess locking even in C code.
              I may be missing your point but I didn't realize you could use file
              locks to synchronize shared memory in any useful way. File locks are
              usually made and released when the file is opened and closed, or at
              best through flock or fcntl calls. Shared memory locks should
              generally be done with mechanisms like futex, that in the no-wait case
              should not involve any system calls.

              Comment

              • sjdevnull@yahoo.com

                #37
                Re: threading support in python

                Paul Rubin wrote:
                "sjdevnull@yaho o.com" <sjdevnull@yaho o.comwrites:
                I think it's even worse. The standard Python library offers
                shared memory, but not cross-process locks.
                File locks are supported by the standard library (at least on Unix,
                I've not tried on Windows). They work cross-process and are a normal
                method of interprocess locking even in C code.
                >
                I may be missing your point but I didn't realize you could use file
                locks to synchronize shared memory in any useful way.
                You can, absolutely. If you're sharing memory through mmap it's
                usually the preferred solution; fcntl locks ranges of an open file, so
                you lock exactly the portions of the mmap that you're using at a given
                time.

                It's not an unusual use at all, Unix programs have used file locks in
                this manner for upwards of a decade--things like the Apache public
                runtime use fcntl or flock for interprocess mutexes, and they're quite
                efficient. (The futexes you mentioned are a very recent Linux
                innovation).

                Comment

                • Paul Rubin

                  #38
                  Re: threading support in python

                  "sjdevnull@yaho o.com" <sjdevnull@yaho o.comwrites:
                  You can, absolutely. If you're sharing memory through mmap it's
                  usually the preferred solution; fcntl locks ranges of an open file, so
                  you lock exactly the portions of the mmap that you're using at a given
                  time.
                  How can it do that without having to touch the PTE for every single
                  page in the range, which might be gigabytes? For that matter, how can
                  it do that on regions smaller than a page? And how does another
                  process query whether a region is locked, without taking a kernel trap
                  if it's locked? This sounds absolutely horrendous compared to a
                  futex, which should usually be just one or two user-mode instructions
                  and no context switches.
                  It's not an unusual use at all, Unix programs have used file locks in
                  this manner for upwards of a decade--things like the Apache public
                  runtime use fcntl or flock for interprocess mutexes, and they're quite
                  efficient. (The futexes you mentioned are a very recent Linux
                  innovation).
                  Apache doesn't use shared memory in the same way that something like a
                  database does, so maybe it can more easily tolerate the overhead of
                  fcntl. Futex is just a somewhat standardized way to do what
                  programmers have done less portably since the dawn of multiprocessors .

                  Comment

                  • mystilleef

                    #39
                    Re: threading support in python

                    You can use multiple processes to simulate threads via an IPC
                    mechanism. I use D-Bus to achieve this.



                    km wrote:
                    Hi all,
                    Are there any alternate ways of attaining true threading in python ?
                    if GIL doesnt go then does it mean that python is useless for
                    computation intensive scientific applications which are in need of
                    parallelization in threading context ?
                    >
                    regards,
                    KM
                    ---------------------------------------------------------------------------
                    On 4 Sep 2006 07:58:00 -0700, bayerj <bayerj@in.tum. dewrote:

                    Comment

                    • Bryan Olson

                      #40
                      Re: threading support in python

                      sjdevnull@yahoo .com wrote:
                      Bryan Olson wrote:
                      >I think it's even worse. The standard Python library offers
                      >shared memory, but not cross-process locks.
                      >
                      File locks are supported by the standard library (at least on Unix,
                      I've not tried on Windows). They work cross-process and are a normal
                      method of interprocess locking even in C code.
                      Ah, O.K. Like Paul, I was unaware how Unix file worked with
                      mmap.


                      --
                      --Bryan

                      Comment

                      • Bryan Olson

                        #41
                        Re: threading support in python

                        I wrote:
                        Ah, O.K. Like Paul, I was unaware how Unix file worked with
                        mmap.
                        Insert "locking" after "file".


                        --
                        --Bryan


                        Comment

                        • lcaamano

                          #42
                          Re: threading support in python

                          Here's a relevant post



                          or

                          http://tinyurl.com/fod9u


                          skip@pobox.com wrote:
                          AndreThis seems to be an important issue and fit for discussion in the
                          Andrecontext of Py3k. What is Guido's opinion?
                          >
                          Dunno. I've never tried channeling Guido before. You'd have to ask him.
                          Well, maybe Tim Peters will know. He channels Guido on a fairly regular
                          basis.
                          >
                          Skip
                          --
                          lpc

                          Comment

                          Working...