944,141 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1749
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 1st, 2009
-2

separate process

Expand Post »
Hi all.


i want to make separate process with python.

for example i have python code. for example:
Python Syntax (Toggle Plain Text)
  1. import time
  2. time.sleep(5)
  3. print "Time Over"
named: t.py

and i want to do all ^^that^^ just on other process
i hope you understand.


AND DONT GIVE ME LINKS PLS. I GOOGLED THAT MUCH.
BUT NOTHING HELPFUL,
just WRITE CODE WHICH WOULD BE HELPFUL FOR ME!
sorry for My english
Similar Threads
Reputation Points: 9
Solved Threads: 1
Light Poster
Dixtosa is offline Offline
38 posts
since Jul 2009
Oct 1st, 2009
1

Re: separate process

One way to do it is to use the subprocess module
python Syntax (Toggle Plain Text)
  1. import subprocess as SP
  2. child_process = SP.Popen(["python", "t.py"])
Reputation Points: 930
Solved Threads: 668
Posting Maven
Gribouillis is offline Offline
2,656 posts
since Jul 2008
Oct 1st, 2009
0

Re: separate process

Not sure what your asking?

Do you mean you want to create:

1. a thread which exists in the current process
2. a new process which exists independently
Reputation Points: 499
Solved Threads: 367
Postaholic
gerard4143 is offline Offline
2,198 posts
since Jan 2008
Oct 1st, 2009
0

Re: separate process

you're not making much sense... Do you want to have that processes running on another thread so you can continue doing something else? Do you just want to execute that little script then after it finishes it moves on? What are you trying to do EXACTLY?
Reputation Points: 35
Solved Threads: 22
Junior Poster
ov3rcl0ck is offline Offline
113 posts
since Sep 2009
Oct 1st, 2009
0

Re: separate process

Gribouillis

and where can i donwload thatmodule?

gerard4143
2


ov3rcl0ck
I want to have that processes running on another thread and ability to continue doing something else.
and
I DONT want just to execute that little script then after it finishes it moves on.
Reputation Points: 9
Solved Threads: 1
Light Poster
Dixtosa is offline Offline
38 posts
since Jul 2009
Oct 1st, 2009
0

Re: separate process

ov3rcl0ck, for example, i have code:


...commands1...
...commands2...
call to t.py and imediately go on next command3
...commands3...
...commands4...

and i think separate process is the best in this time
Last edited by Dixtosa; Oct 1st, 2009 at 4:29 pm.
Reputation Points: 9
Solved Threads: 1
Light Poster
Dixtosa is offline Offline
38 posts
since Jul 2009
Oct 1st, 2009
0

Re: separate process

Click to Expand / Collapse  Quote originally posted by Dixtosa ...
Gribouillis

and where can i donwload thatmodule?

gerard4143
2


ov3rcl0ck
I want to have that processes running on another thread and ability to continue doing something else.
and
I DONT want just to execute that little script then after it finishes it moves on.
Click to Expand / Collapse  Quote originally posted by Dixtosa ...
ov3rcl0ck, for example, i have code:


...commands1...
...commands2...
call to t.py and imediately go on next command3
...commands3...
...commands4...

and i think separate process is the best in this time
First off Subprocess is a default module for python, next subprocess doesn't spawn a new thread, you need the multithreading module that comes default with the interpreter, also knowing object orientated programming will help. Try this little example:

Python Syntax (Toggle Plain Text)
  1. import threading
  2.  
  3. class THREAD(threading.Thread):
  4. def __init__(self,ARG1,ARG2):
  5. #If you change the arugments of __init__ modify the bellow also
  6. self.arg1=ARG1
  7. self.arg2=ARG2
  8. def run(self):
  9. #THIS IS WERE YOUR CODE GOES!
  10.  
  11. t=THREAD(ARG1,ARG2)
  12. t.start()
  13. t.join()

The easiest way to do it is make a thread out of a function but this will lose alot of functionality and is a messy way of doing things IMO. Here it is:
Python Syntax (Toggle Plain Text)
  1. import threading,thread
  2.  
  3. def THREAD(ARG1,ARG2):
  4. #YOUR CODE
  5. thread.start_new_thread(THREAD, (ARG1,ARG2))
Reputation Points: 35
Solved Threads: 22
Junior Poster
ov3rcl0ck is offline Offline
113 posts
since Sep 2009
Oct 2nd, 2009
0

Re: separate process

code:
Python Syntax (Toggle Plain Text)
  1. import threading
  2.  
  3. class THREAD(threading.Thread):
  4. def __init__(self,ARG1,ARG2):
  5. #If you change the arugments of __init__ modify the bellow also
  6. self.arg1=ARG1
  7. self.arg2=ARG2
  8. def run(self):
  9. print "RUN"
  10. #THIS IS WERE YOUR CODE GOES!
  11. ARG1,ARG2=1,2
  12.  
  13. t=THREAD(ARG1,ARG2)
  14. t.start()
  15. t.join()

error:
Traceback (most recent call last):
File "D:\Desktop_MARI\threading\th.py", line 14, in <module>
t.start()
File "C:\Python25\lib\threading.py", line 432, in start
raise RuntimeError("thread.__init__() not called")
RuntimeError: thread.__init__() not called
Reputation Points: 9
Solved Threads: 1
Light Poster
Dixtosa is offline Offline
38 posts
since Jul 2009
Oct 2nd, 2009
0

Re: separate process

Python Syntax (Toggle Plain Text)
  1. import threading
  2.  
  3. class THREAD(threading.Thread):
  4. def __init__(self,ARG1,ARG2):
  5. threading.Thread.__init__(self)
  6. #If you change the arugments of __init__ modify the bellow also
  7. self.arg1=ARG1
  8. self.arg2=ARG2
  9. def run(self):
  10. print "RUN"
  11. #THIS IS WERE YOUR CODE GOES!
  12. ARG1,ARG2=1,2
  13.  
  14. t=THREAD(ARG1,ARG2)
  15. t.start()
  16. t.join()

Forgot a line. But you do realize this is an example and i posted it so you can adjust it to your needs, if you don't understand it you're not ready for threading, so this script probably won't work, and if it does its not gonna do anything.If you don't understand it you're not ready for threading.
Reputation Points: 35
Solved Threads: 22
Junior Poster
ov3rcl0ck is offline Offline
113 posts
since Sep 2009
Oct 2nd, 2009
0

Re: separate process

overclock, that isnot what i need.however,thank you .

Gribouillis, that was usefull. however i want to know how to multiproceess. i dont believe that it isnt possible.
Reputation Points: 9
Solved Threads: 1
Light Poster
Dixtosa is offline Offline
38 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Using linalg.solve_banded
Next Thread in Python Forum Timeline: how to install and implement the django web framework on Mac OS





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC