Processes.

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

    Processes.

    Hi

    I've done some projects in python for my work which invole some test
    scripts etc. All quite basic stuff, I find python a good language to
    work in but have come up against a brick wall. I'm been searching
    google for hours about processes pids etc. My problem is as follows
    the main problem code can be seen below :

    server = uc_server(HOST_ str, PORT_num)
    while 1:
    asyncore.poll(S ERVER_TIMEOUT)

    # Only pops queue when the current item is blank.
    if (server.current _queue_item == [0,"","",["",0],["",""]]):
    # Pops a queue item if there are any queue items to get.
    Temp_Current_It em = MainQueue.Pop()
    if (Temp_Current_I tem != N):
    server.current_ queue_item = Temp_Current_It em

    Execute_Command _str =
    ServerSupport.C reateCommand(Te mp_Current_Item )

    # Only executes if on a win32 platform.
    if (sys.platform == "win32")and(Exe cute_Command_st r != N):
    output, input = popen2("cmd.exe ")
    input.write(Exe cute_Command_st r+"\n")
    input.write("ex it\n")

    while 1:
    text = output.readline ()
    if text:
    print text
    else:
    # Sets the current queue item to blank.
    server.current_ queue_item =
    [0,"","",["",0],["",""]]
    break

    What I want to have is a server which is multi platform win32,
    unix(lots of differnt sorts and may be mac later but forget mac for
    now.) that people can telnet onto leave a job, and then the server
    runs the jobs one at a time.
    What I have is a server that people can telnet on to leave a job, the
    server will execute it and keep executing it until it is done. I
    thought that maybe the poll thing would sort this out by switching
    from the main body of the script to the server part of the script, but
    it didn't. The way that I use popen2 is my fav. way of executing
    processes as I can catcher all output. What would be really good if I
    could execute commands or scripts by using child processes and
    searching for there pids this way I would know whats running on the
    box at any one time.
    There's loads about pids processes on google but it mainly in unix, I
    mainly want it in win32 which there is hardly anything about.

    Please Please Help

    TIA
    TTFN
    Guy
  • Trent Mick

    #2
    Re: Processes.


    Guy,

    Basically working with processes in a cross-platform manner is a pain.
    :) Yes PIDs are more of a Linux/Unix thing. I think they do exist to a
    degree on Windows but that would only be as part of Windows' weak posix
    compliance layer. In Windows you generally want to talk about process
    handles. However, Python's standard process handling stuff doesn't
    generally expose the handles for started processes. I have a module
    called process.py that might help do what you want to do. Give it a try:


    Cheers,
    Trent


    [Guy wrote][color=blue]
    > Hi
    >
    > I've done some projects in python for my work which invole some test
    > scripts etc. All quite basic stuff, I find python a good language to
    > work in but have come up against a brick wall. I'm been searching
    > google for hours about processes pids etc. My problem is as follows
    > the main problem code can be seen below :
    >
    > server = uc_server(HOST_ str, PORT_num)
    > while 1:
    > asyncore.poll(S ERVER_TIMEOUT)
    >
    > # Only pops queue when the current item is blank.
    > if (server.current _queue_item == [0,"","",["",0],["",""]]):
    > # Pops a queue item if there are any queue items to get.
    > Temp_Current_It em = MainQueue.Pop()
    > if (Temp_Current_I tem != N):
    > server.current_ queue_item = Temp_Current_It em
    >
    > Execute_Command _str =
    > ServerSupport.C reateCommand(Te mp_Current_Item )
    >
    > # Only executes if on a win32 platform.
    > if (sys.platform == "win32")and(Exe cute_Command_st r != N):
    > output, input = popen2("cmd.exe ")
    > input.write(Exe cute_Command_st r+"\n")
    > input.write("ex it\n")
    >
    > while 1:
    > text = output.readline ()
    > if text:
    > print text
    > else:
    > # Sets the current queue item to blank.
    > server.current_ queue_item =
    > [0,"","",["",0],["",""]]
    > break
    >
    > What I want to have is a server which is multi platform win32,
    > unix(lots of differnt sorts and may be mac later but forget mac for
    > now.) that people can telnet onto leave a job, and then the server
    > runs the jobs one at a time.
    > What I have is a server that people can telnet on to leave a job, the
    > server will execute it and keep executing it until it is done. I
    > thought that maybe the poll thing would sort this out by switching
    > from the main body of the script to the server part of the script, but
    > it didn't. The way that I use popen2 is my fav. way of executing
    > processes as I can catcher all output. What would be really good if I
    > could execute commands or scripts by using child processes and
    > searching for there pids this way I would know whats running on the
    > box at any one time.
    > There's loads about pids processes on google but it mainly in unix, I
    > mainly want it in win32 which there is hardly anything about.
    >
    > Please Please Help
    >
    > TIA
    > TTFN
    > Guy
    > --
    > http://mail.python.org/mailman/listinfo/python-list[/color]

    --
    Trent Mick
    TrentM@ActiveSt ate.com

    Comment

    Working...