473,503 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Let My Terminal Go

Hello,

A user of my application points me to a behavior in gVim,
the text editor, that I would like to implement in my
application.

When gVim is launched from a shell terminal, it completely
frees the terminal. You can continue to use the terminal for
whatever purpose you wish, including closing and exiting it,
without any effect on the running gVim instance.

How do I implement this in my application written in python?
I would like to believe it does not involve me forking my
application in a new process. Maybe there is signal I can
send to the operating system to achieve this, right?

Your help is appreciated.

Thanks

Oct 11 '05 #1
14 1577
On Mon, 2005-10-10 at 22:58 -0700, my********@gmail.com wrote:
Hello,

A user of my application points me to a behavior in gVim,
the text editor, that I would like to implement in my
application.

When gVim is launched from a shell terminal, it completely
frees the terminal. You can continue to use the terminal for
whatever purpose you wish, including closing and exiting it,
without any effect on the running gVim instance.

How do I implement this in my application written in python?
I would like to believe it does not involve me forking my
application in a new process. Maybe there is signal I can
send to the operating system to achieve this, right?


gvim forks. Why do you want to avoid it?

import os, sys

pid = os.fork()
if pid !=0:
# exit parent
sys.exit(0)
# child continues
Oct 11 '05 #2
my********@gmail.com enlightened us with:
When gVim is launched from a shell terminal, it completely frees the
terminal. [...] How do I implement this in my application written in
python?


Using fork() and by catching the HUP signal.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Oct 11 '05 #3
"my********@gmail.com" <my********@gmail.com> writes:
Hello,

A user of my application points me to a behavior in gVim,
the text editor, that I would like to implement in my
application.

When gVim is launched from a shell terminal, it completely
frees the terminal. You can continue to use the terminal for
whatever purpose you wish, including closing and exiting it,
without any effect on the running gVim instance.

How do I implement this in my application written in python?
I would like to believe it does not involve me forking my
application in a new process. Maybe there is signal I can
send to the operating system to achieve this, right?


Several things need to happen.

First, you need to take yourself out of the session you are in. To do
that, you use the setsid system call. This is available in python as
os.setsid.

Last, you need to detach your process from the terminal. You do that
by closing all the file descriptors you have that reference it. stdin,
stdout and stderr should do the trick. The standard trick is to set
set them to /dev/null. This has to happen last, so that if there are
problems in the second step, writing to stderr about it does some
good.

Second, you need to tell the shell that launched you that it can
continue. The standard way to do this is to fork your process, and
have the parent exit. That causes the parent shell to think your
process is dead, and so forget about it completely. There are other
ways to do this, but they aren't as reliable.

The easy way to do all these things - from C, anyway - is with
daemon(3). That isn't wrapped as part of the Python library. The
easiest way to solve your problem may be write a wrapper for that
call. If daemon exists on enough systems, submitting your wrapper as a
patch to the os modulee would be appropriate.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Oct 11 '05 #4
On 10 Oct 2005 22:58:08 -0700
my********@gmail.com wrote:
How do I implement this in my application written in python?


Google for "python daemonize".

--
jk
Oct 11 '05 #5
Hello,

Thank you. That's all I needed. For some reason, I had always assumed
forking was an expensive process. I guess I was ill-informed.

Oct 11 '05 #6
Hello,

Thanks to all the responders and helpers on the group. I'm learning
everyday.

Thanks

Oct 11 '05 #7
Mike Meyer wrote:
The easy way to do all these things - from C, anyway - is with
daemon(3). That isn't wrapped as part of the Python library. The
easiest way to solve your problem may be write a wrapper for that
call. If daemon exists on enough systems, submitting your wrapper as a
patch to the os modulee would be appropriate.


I think the deamon() library call only exists on the BSDs. Anyway, there
it is implemented with a fork() call and some additional code to close
std descriptors, so there's no practical difference between calling
deamon() and fork() by yourself...
Oct 11 '05 #8
On Tue, 11 Oct 2005 03:30:23 -0700, Mystilleef wrote:
Hello,

Thank you. That's all I needed. For some reason, I had always assumed
forking was an expensive process. I guess I was ill-informed.


In a loop, yes, it's expensive.

Done once, it's usually not unacceptable.

Oct 11 '05 #9
On Tue, 11 Oct 2005 22:01:23 GMT, Dan Stromberg <st******@dcs.nac.uci.edu> wrote:
On Tue, 11 Oct 2005 03:30:23 -0700, Mystilleef wrote:
Hello,

Thank you. That's all I needed. For some reason, I had always assumed
forking was an expensive process. I guess I was ill-informed.
In a loop, yes, it's expensive.


It depends on what you mean by expensive -- web servers can fork for each
HTTP request they get, in real-world scenarios, and get away with it.
Done once, it's usually not unacceptable.


In fact, I can't think of a scenario where it /would/ be unacceptable ;-)

But back to the original problem: I can't really see why anybody would need
the "let my terminal go" feature. Is there a reason why 'gvim foo.txt&'
isn't good enough?

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Oct 13 '05 #10
Jorgen Grahn <jg*********@algonet.se> writes:
It depends on what you mean by expensive -- web servers can fork for each
HTTP request they get, in real-world scenarios, and get away with it.


This is OS dependent. Forking on Windows is much more expensive than
forking on Linux.
Oct 13 '05 #11
On 2005-10-13, Paul Rubin <> wrote:
Jorgen Grahn <jg*********@algonet.se> writes:
It depends on what you mean by expensive -- web servers can fork for each
HTTP request they get, in real-world scenarios, and get away with it.


This is OS dependent. Forking on Windows is much more
expensive than forking on Linux.


Under VMS, fork/exec was so expensive that the Bourne shell
implimentation in DECShell executed "simple" commands in the
shell's process rather than do a fork/exec. Shell scripts that
used pipes or similar constructs requiring fork/exec ran _very_
slowly under DECShell.

Since the NT kernel is descended from VMS, I'm not surprised
that a fork is expensive.

--
Grant Edwards grante Yow! Why are these
at athletic shoe salesmen
visi.com following me??
Oct 13 '05 #12
Grant Edwards <gr****@visi.com> writes:
Since the NT kernel is descended from VMS, I'm not surprised
that a fork is expensive.


Apache 2.x supports concurrency via threading as an alternative to
forking, basically in order to get acceptable performance on Windows.
Oct 13 '05 #13
Jorgen Grahn wrote:
Done once, it's usually not unacceptable.


In fact, I can't think of a scenario where it /would/ be unacceptable ;-)


if you're stuck on a system that doesn't use copy-on-write ?

</F>

Oct 13 '05 #14
On 13 Oct 2005 09:54:44 -0700, Paul Rubin <http> wrote:
Jorgen Grahn <jg*********@algonet.se> writes:
It depends on what you mean by expensive -- web servers can fork for each
HTTP request they get, in real-world scenarios, and get away with it.


This is OS dependent. Forking on Windows is much more expensive than
forking on Linux.


Forking, to me, means doing what the Unix fork(2) system call does. Since
AFAIK there is no corresponding Win32 call, I assumed the original poster
was on Unix.

But now I see that he didn't use the word "fork"; someone else in the thread
did ...

You are correct, of course; the cost of spawning processes varies a lot
between OSes, and it's distinctly higher on Windows compared to Unixes in
general and Linux in particular.

(BTW, Eric Raymond argues that low-cost spawning is an important
characteristic of an OS: see
http://www.faqs.org/docs/artu/ch03s01.html#id2892171 )

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Oct 15 '05 #15

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

Similar topics

4
4053
by: flamesrock | last post by:
First, I'm very new to gui programming, so please go lightly on me :) Ok, so far I've settled on wxPython, and what I'd like to do as a first leap is *convert* a text program into a gui program....
3
5550
by: Josh Schmidt | last post by:
How can one set the terminal services profile and home directory path in AD using VB.NET? I can set the usual profile paths, but terminal services properties are not supported with ADSI. Any...
5
7557
by: TPoise! | last post by:
Using: .NET 1.1, Visual Studio 2003, C#, Microsoft Windows 2000 Server (SP4 and all latest windows updates), Terminal Server running in application mode. I have a C# application that I've...
8
2713
by: OHM | last post by:
Hi peoples, I dont know where to place this question, so as I know you guys are all resourceful experts, I thought I would try here. I am writing some code which will be run usingh remote...
6
4027
by: Atley | last post by:
I have a Terminal Services server running Windows 2000 Server. I need to be able to identify, in my application on that server, which client computer is addressing that server and running that...
20
10808
by: Joel Hedlund | last post by:
Hi all! I use python for writing terminal applications and I have been bothered by how hard it seems to be to determine the terminal size. What is the best way of doing this? At the end I've...
4
1986
by: fivestars | last post by:
Hi there. I'm computer science student at the end of my degree. I'm new about python. I've a question for all of you. Do you know how to write, from python code, on a unix(linux) terminal...
3
1735
by: shawn | last post by:
In the past I have had SQL and Terminal server on the same PC. With SQL and Windows 2003 Terminal server, you can not have them on the same PC. How can I make this work with SQL and Terminal and...
7
3038
by: mike | last post by:
We have numerous Access 97 apps that we run on our Terminal Server, but two apps in particular is giving us a problem. The problem we are running into is when you select a drop down menu, it errors...
16
3973
by: =?Utf-8?B?RHdlZWJlcmVsbGE=?= | last post by:
I created an Access 2007 application for my customer. The application is shared by three employees on a server. It maintains a contact list including financial data and social security numbers. ...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
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
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
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
7468
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
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.