hide python window, con'td

B

Bell, Kevin

Great! And now that it's hiding w/ .pyw, how would I kill it if I want?
Just log off, or is there a better way?

Kevin
 
L

Larry Bates

Something that runs all day in the background is a perfect candidate
for being turned into a Service. That and servicemanager has a good
way of managing the task so that it doesn't take up lots of excess
CPU cycles that a "normal" application would take while sleeping
or unnecessarily looping. Pick up a copy of Mark Hammond's Python
Programming on Win32 book for example services in Python. You could
then start/stop the service with service manager or with net start/
net stop commands.

-Larry Bates
 
R

Robin Becker

Larry said:
Something that runs all day in the background is a perfect candidate
for being turned into a Service. That and servicemanager has a good
way of managing the task so that it doesn't take up lots of excess
CPU cycles that a "normal" application would take while sleeping
or unnecessarily looping. Pick up a copy of Mark Hammond's Python
Programming on Win32 book for example services in Python. You could
then start/stop the service with service manager or with net start/
net stop commands.

-Larry Bates
It is possible to get a background process in windows especially with
Python-2.4, but it's fairly hard.

try using

python runner.py dingo.py

where

###### runner.py
def bgScript(script,scriptArgs):
from _subprocess import CreateProcess
class STARTUPINFO:
dwFlags = 0
hStdInput = None
hStdOutput = None
hStdError = None
class pywintypes:
error = IOError
import sys
exe = sys.executable.replace('n.exe','nw.exe')
startupinfo = STARTUPINFO()
args = ''.join([' "%s"' % a for a in scriptArgs])
cmd = '"%s" "%s" %s' % (exe,script,args)
try:
hp, ht, pid, tid = CreateProcess(None, cmd,
# no special security
None, None,
0, #don't inherit standard handles
0x208,
None,
None,
startupinfo)
except pywintypes.error, e:
print str(e)

if __name__=='__main__':
import sys
bgScript(sys.argv[1],sys.argv[2:])
###### dingo.py
if __name__=='__main__':
import time
for i in xrange(15):
time.sleep(1)
######

dingo.py shoul be running in the background detached from the console.
Of course as others point out, the official way to do this stuff is to
use all the M$ paraphernalia and have stuff start up at boot time etc etc.
 
L

Larry Bates

It is just the nature of "things that run in the background all
day" to be things that should probably be daemons or services.
They almost always sleep, check, process, sleep, ... and as
windows services do that better than processes in loops that
sleep. They are daunting at first, but services aren't really
all that hard to write after you first one.

Larry Bates

Robin said:
Larry said:
Something that runs all day in the background is a perfect candidate
for being turned into a Service. That and servicemanager has a good
way of managing the task so that it doesn't take up lots of excess
CPU cycles that a "normal" application would take while sleeping
or unnecessarily looping. Pick up a copy of Mark Hammond's Python
Programming on Win32 book for example services in Python. You could
then start/stop the service with service manager or with net start/
net stop commands.

-Larry Bates
It is possible to get a background process in windows especially with
Python-2.4, but it's fairly hard.

try using

python runner.py dingo.py

where

###### runner.py
def bgScript(script,scriptArgs):
from _subprocess import CreateProcess
class STARTUPINFO:
dwFlags = 0
hStdInput = None
hStdOutput = None
hStdError = None
class pywintypes:
error = IOError
import sys
exe = sys.executable.replace('n.exe','nw.exe')
startupinfo = STARTUPINFO()
args = ''.join([' "%s"' % a for a in scriptArgs])
cmd = '"%s" "%s" %s' % (exe,script,args)
try:
hp, ht, pid, tid = CreateProcess(None, cmd,
# no special security
None, None,
0, #don't inherit standard handles
0x208,
None,
None,
startupinfo)
except pywintypes.error, e:
print str(e)

if __name__=='__main__':
import sys
bgScript(sys.argv[1],sys.argv[2:])
###### dingo.py
if __name__=='__main__':
import time
for i in xrange(15):
time.sleep(1)
######

dingo.py shoul be running in the background detached from the console.
Of course as others point out, the official way to do this stuff is to
use all the M$ paraphernalia and have stuff start up at boot time etc etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,281
Latest member
DaneLxa72

Latest Threads

Top