473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Tough Spawn Problem

I'm trying to use Python and PyGTK + Glade, along with Bash. I want to
make a GUI for the Linux vpnclient command-line tool. (Look for
linux-vpnclient.tar.gz on the Internet if you are curious.) Anyway,
this vpnclient tool connects to VPN and then stays locked like that
while the VPN connection is running. What I was trying to do was either
spawn it and then use another command-line tool to check on its status,
or shell the process and redirect all its output text to the GTK
textbox in the GUI. Here's the problems I found with that:

* Spawn - This seems to spawn the process okay, but when the vpnclient
connection is finally loaded, it holds the process and the GUI cannot
return to being responsive -- it locks the GUI up, essentially. I tried
os.NO_WAIT and os.DETACH but os.NO_WAIT was no solution and os.DETACH
only works in the documentation, not in my version of Python.

* Shell - This seems to do the same thing as spawn but instead of
sending output to a console, it sends the output into a console-less
space. Then, because the VPN connection is locked-in, it also holds the
GUI up and hangs it.

I tried using the " &" operator but that seemed to have no effect in
fixing this problem.

What's the trick?

Jul 18 '05 #1
1 2101
By using os.spawn* and the os.P_NOWAIT, the spawn function will return
immediately, with the return value being the PID of the new process.
Later, you can use os.kill() to force the program to terminate,
os.waitpid() to retrieve the exit status if it has terminated, or you
could use the signal module to wait for SIGCHLD to be delivered at the
time the child terminates.

With os.spawn*, the child's open files (including stdin and stdout) are
the same as the parent's; using the popen2 module, you can send the
program input and capture its output too.

Here's the program I ran on Linux (Fedora Core 2 / Python 2.3) to show
that os.P_NOWAIT works fine:
import os
pid = os.spawnv(os.P_NOWAIT, "/bin/sh",
["sh", "-c", "sleep 1; echo spawned program"])
print "child is pid", pid
print "waitpid result is", os.waitpid(pid, 0)
and the output is
$ python /tmp/googlemike.py
child is pid 13874
spawned program
waitpid result is (13874, 0)
the fact that "spawned program" is printed after "child is pid NNNNN"
shows that the python program continues executing while the child is
working (or, in this case, sleeping).

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFCKw3XJd01MZaTXX0RAqwDAKCN/ya+3R0Jy+O3sJSF1TBnhjV40ACgrZKg
zBbog4AwadFOuxx/6SgqpCA=
=EObs
-----END PGP SIGNATURE-----

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark Roach | last post by:
I am using the daemonize (double-fork) code from the cookbook, and have bumped into a strange issue. This is what my program is doing: def main(): ... useful things ... os.popen('/usr/bin/lp -d...
7
by: C Gillespie | last post by:
Dear All, I have a function def printHello(): fp = open('file','w') fp.write('hello') fp.close() I would like to call that function using spawn or fork. My questions are:
2
by: Derek Basch | last post by:
Hello, *First question* If the syntax of spawnl is: spawnl(mode, path, ...) Why does everyone write it like:
2
by: tmb | last post by:
- Want to open a 2nd browser window when someone clinks a link with the link content inside it. - Want to control window size - Want all tool bars so only blue bar at top shows - Can I put my...
23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
3
by: Paul | last post by:
Hi all. Can someone provide some help on the following as there seems to be many different methods of acheiving the same outcome. Basically I am trying to develop a web service which will...
3
by: Sinan Nalkaya | last post by:
hi, i am using os.spawn function, it works well but i need a flag that allows function return the process id with exit/error code, is there any or how can i do it, i can replace spawn with...
3
by: Bierny | last post by:
Hi, I am quite new to Python but i found it really interesting and useful so I am trying to write even the smallest tools in this language. During this passion of creating everything in Python I get...
4
by: Brendan Miller | last post by:
I want to spawn a child process based on an external executable that I have the path for. I then want to wait on that executable, and capture it's output. In the os module, fork is only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.