Threading and Windows.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Kelley

    #16
    Re: Threading and Windows.

    If you are using wxPython you might want to check out this little package:



    look for LongRunningTask s at the bottom.

    -brian

    Comment

    • Jorge Godoy

      #17
      Re: Threading and Windows.

      Dennis Lee Bieber <wlfraed@ix.net com.com> writes:
      [color=blue]
      > Jorge Godoy fed this fish to the penguins on Tuesday 30 September 2003
      > 09:01 am:
      >[color=green]
      >>
      >> The most interesting thing is that I get an error in Windows but I
      >> don't get such an error in Linux.
      >>[/color]
      > spawnv() is probably a direct match with a unix/linux system call, so
      > the arguments are just being passed on -- and what linux does when it
      > gets the address of a string where it expected an integer constant is
      > unknown to me (probably sees the address /as/ the integer, and since
      > P_WAIT is 0, the runtime is treating any non-zero to be the equivalent
      > of P_NOWAIT)[/color]

      The behaviour of treating it as nonzero would be expected. What
      happens is the opposite of that as I described before: the program
      hangs as if it received P_WAIT.


      I think that they check explicitly for P_NOWAIT and treat anything
      different as zero (P_WAIT).


      The principle of least surprise was violated, IMVHO as a newbie on
      that area. :-)


      See you,
      --
      Godoy. <godoy@metalab. unc.edu>

      Comment

      • Jorge Godoy

        #18
        Re: Threading and Windows.

        Brian Kelley <bkelley@wi.mit .edu> writes:
        [color=blue]
        > If you are using wxPython you might want to check out this little package:
        >
        > http://staffa.wi.mit.edu/people/kelley/
        >
        > look for LongRunningTask s at the bottom.
        >
        > -brian[/color]

        I didn't knew this address but I got something like that from


        It didn't solve my problem but thanks for this new pointer.

        In my case I really needed something that ran a new proccess.

        --
        Godoy. <godoy@metalab. unc.edu>

        Comment

        • Dennis Lee Bieber

          #19
          Re: Threading and Windows.

          Dennis Lee Bieber fed this fish to the penguins on Tuesday 30 September
          2003 10:17 am:

          [color=blue][color=green]
          >>[/color]
          > spawnv() is probably a direct match with a unix/linux system[/color]

          Okay, I took some time at work to look at the source for os.py... My
          assumptions are totally backwards...

          From my email to myself:

          Had a reversal... spawnv() does not exit on Linux, which uses
          combination of (see os.py for actual code):

          pid = fork()
          if not pid: #new process
          execv() #replace with desired program
          else:
          if mode == P_NOWAIT:
          return pid
          while 1: # why the loop?
          status = waitpid(pid, 0)
          #tests for status return


          Since 'P_NOWAIT' is not equal to os.P_NOWAIT, Linux defaults to
          performing the wait operation.

          It is on Windows where a low-level _spawnv() exists,
          int _spawnv( int mode, const char *cmdname, const char *const *argv );
          and the error is raised when Python tries to convert the string
          'P_NOWAIT' into the integer mode for the direct call.

          --[color=blue]
          > =============== =============== =============== =============== == <
          > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
          > wulfraed@dm.net | Bestiaria Support Staff <
          > =============== =============== =============== =============== == <
          > Bestiaria Home Page: http://www.beastie.dm.net/ <
          > Home Page: http://www.dm.net/~wulfraed/ <[/color]

          Comment

          • Bengt Richter

            #20
            Re: [SOLVED] Re: Threading and Windows.

            On Tue, 30 Sep 2003 10:54:57 -0300, Jorge Godoy <godoy@metalab. unc.edu> wrote:
            [color=blue]
            >Dennis Lee Bieber <wlfraed@ix.net com.com> writes:
            >[color=green]
            >> Jorge Godoy fed this fish to the penguins on Monday 29 September 2003
            >> 07:31 pm:
            >>[color=darkred]
            >>>
            >>> This isn't the behaviour I found here on a Linux box. The caller
            >>> process got 'stuck' and only worked again when the called proccess
            >>> ended.
            >>>[/color]
            >> Strange...[/color]
            >
            >OK... I tracked it down and found the 'P_NOWAIT' didn't work. I
            >replaced it with '1' (no quotes) and everything went fine on bot OSs.
            >[/color]
            What is os.P_NOWAIT on your system? It looks like '1' (no quotes) on my system:
            [color=blue][color=green][color=darkred]
            >>> import os
            >>> os.name[/color][/color][/color]
            'nt'[color=blue][color=green][color=darkred]
            >>> os.P_NOWAIT[/color][/color][/color]
            1
            [color=blue]
            >The error message on Windows helped finding it out (it said that an
            >integer was expected but I got nothing on Linux).
            >[color=green]
            >> You might have to explicitly invoke the python executable, and pass
            >> /it/ the .py file as the first argument[/color]
            >
            >It ended up like this:
            >
            > os.spawnv(1, 'c:/python22/pythonw.exe', ['c:/python22/pythonw.exe', 'another.py', parameter])[/color]
            So one would think

            os.spawnv(os.P_ NOWAIT, 'c:/python22/pythonw.exe',
            ['c:/python22/pythonw.exe', 'another.py', parameter])

            would work, except I note that os.P_NOWAIT is not defined in Python 1.5.2 on Linux (slackware).
            Gotta upgrade one of these days... My nt python is 2.3 though, but I don't suppose that's changed
            since the 2.2 you are apparently running on windows??

            Regards,
            Bengt Richter

            Comment

            • Jorge Godoy

              #21
              Re: [SOLVED] Re: Threading and Windows.

              bokr@oz.net (Bengt Richter) writes:
              [color=blue][color=green]
              >>OK... I tracked it down and found the 'P_NOWAIT' didn't work. I
              >>replaced it with '1' (no quotes) and everything went fine on bot OSs.
              >>[/color]
              > What is os.P_NOWAIT on your system? It looks like '1' (no quotes) on my system:
              >[color=green][color=darkred]
              > >>> import os
              > >>> os.name[/color][/color]
              > 'nt'[color=green][color=darkred]
              > >>> os.P_NOWAIT[/color][/color]
              > 1[/color]

              It is '1', just as in yours. I was saying that there's no 'P_NOWAIT'
              (with quotes and no 'os.' prefix). :-)
              [color=blue]
              > So one would think
              >
              > os.spawnv(os.P_ NOWAIT, 'c:/python22/pythonw.exe',
              > ['c:/python22/pythonw.exe', 'another.py', parameter])[/color]

              Exactly. In fact it ended up as (this is in a separate method on the
              main program):

              if (sys.platform == 'win32'):
              python = 'c:/python22/pythonw.exe'
              os.spawnv(os.P_ NOWAIT, python, [python, program, parameter])
              else:
              os.spawnv(os.P_ NOWAIT, program, [program, parameter])
              [color=blue]
              > would work, except I note that os.P_NOWAIT is not defined in Python 1.5.2 on Linux (slackware).
              > Gotta upgrade one of these days... My nt python is 2.3 though, but I don't suppose that's changed
              > since the 2.2 you are apparently running on windows??[/color]

              I'm running 2.2 on both platforms and with the 'os.' prefix everything
              worked. :-)


              Thanks,
              --
              Godoy. <godoy@metalab. unc.edu>

              Comment

              • Tim Evans

                #22
                Re: [SOLVED] Re: Threading and Windows.

                Jorge Godoy <godoy@metalab. unc.edu> writes:[color=blue]
                > [snip]...it ended up as (this is in a separate method on the main
                > program):
                >
                > if (sys.platform == 'win32'):
                > python = 'c:/python22/pythonw.exe'
                > os.spawnv(os.P_ NOWAIT, python, [python, program, parameter])
                > else:
                > os.spawnv(os.P_ NOWAIT, program, [program, parameter])[/color]

                You should probably just be using this on both systems:

                os.spawnv(os.P_ NOWAIT, sys.executable, [sys.executable, program, parameter])

                --
                Tim Evans

                Comment

                • Jorge Godoy

                  #23
                  Re: [SOLVED] Re: Threading and Windows.

                  Tim Evans <t.evans@paradi se.net.nz> writes:
                  [color=blue]
                  > Jorge Godoy <godoy@metalab. unc.edu> writes:[color=green]
                  >> [snip]...it ended up as (this is in a separate method on the main
                  >> program):
                  >>
                  >> if (sys.platform == 'win32'):
                  >> python = 'c:/python22/pythonw.exe'
                  >> os.spawnv(os.P_ NOWAIT, python, [python, program, parameter])
                  >> else:
                  >> os.spawnv(os.P_ NOWAIT, program, [program, parameter])[/color]
                  >
                  > You should probably just be using this on both systems:
                  >
                  > os.spawnv(os.P_ NOWAIT, sys.executable, [sys.executable, program, parameter])[/color]

                  VERY interesting.

                  I think that with that I can avoid checkin the OS the software will be
                  running in.

                  Thanks.


                  See you,
                  --
                  Godoy. <godoy@metalab. unc.edu>

                  Comment

                  Working...