| | |
separate process
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 1
Hi all.
i want to make separate process with python.
for example i have python code. for example:
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
i want to make separate process with python.
for example i have python code. for example:
Python Syntax (Toggle Plain Text)
import time time.sleep(5) print "Time Over"
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
One way to do it is to use the subprocess module
python Syntax (Toggle Plain Text)
import subprocess as SP child_process = SP.Popen(["python", "t.py"])
•
•
Join Date: Sep 2009
Posts: 108
Reputation:
Solved Threads: 12
•
•
•
•
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.
•
•
•
•
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
Python Syntax (Toggle Plain Text)
import threading class THREAD(threading.Thread): def __init__(self,ARG1,ARG2): #If you change the arugments of __init__ modify the bellow also self.arg1=ARG1 self.arg2=ARG2 def run(self): #THIS IS WERE YOUR CODE GOES! t=THREAD(ARG1,ARG2) t.start() 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)
import threading,thread def THREAD(ARG1,ARG2): #YOUR CODE thread.start_new_thread(THREAD, (ARG1,ARG2))
•
•
Join Date: Jul 2009
Posts: 36
Reputation:
Solved Threads: 1
code:
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
Python Syntax (Toggle Plain Text)
import threading class THREAD(threading.Thread): def __init__(self,ARG1,ARG2): #If you change the arugments of __init__ modify the bellow also self.arg1=ARG1 self.arg2=ARG2 def run(self): print "RUN" #THIS IS WERE YOUR CODE GOES! ARG1,ARG2=1,2 t=THREAD(ARG1,ARG2) t.start() 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
•
•
Join Date: Sep 2009
Posts: 108
Reputation:
Solved Threads: 12
Python Syntax (Toggle Plain Text)
import threading class THREAD(threading.Thread): def __init__(self,ARG1,ARG2): threading.Thread.__init__(self) #If you change the arugments of __init__ modify the bellow also self.arg1=ARG1 self.arg2=ARG2 def run(self): print "RUN" #THIS IS WERE YOUR CODE GOES! ARG1,ARG2=1,2 t=THREAD(ARG1,ARG2) t.start() 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.
![]() |
Similar Threads
- Reading keyboard from background process (C++)
- Disabling a service? (Geeks' Lounge)
- Running PHP scripts in backround (PHP)
- small program request (C++)
- .avi file playing (C++)
- adobe acrobat and distiller upgrade advice (Mac Software)
- XP Explorer Problem (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: Using linalg.solve_banded
- Next Thread: how to install and implement the django web framework on Mac OS
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt ansi anti apache approximation array backend basic beginner book builtin calculator chmod code converter countpasswordentry curved dan08 dictionaries dictionary dynamic examples excel file filename float format ftp function gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin port prime programming progressbar projects py2exe pygame pyqt pysimplewizard python random recursion recursive redirect refresh scrolledtext software ssh stamp statictext statistics string strings table terminal text textarea thread threading time tkinter tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable windows wordgame wxpython






