Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Starting New Process

Reply
Thread Tools

Starting New Process

 
 
D
Guest
Posts: n/a
 
      06-01-2006
Hello, I need to write a server program that performs the following
tasks:

1) Listens on TCP port 5555 for a connection
2) When client connects, launches application (for example, vi), then
closes connection with client
3) Goes back to listening on TCP port 5555 for an incoming connection

The main thing I need to make sure of is that when the server program
closes, that the applications that were launched remain running (i.e. I
would need to launch them independently of the server program). Any
help as to how to do this would be greatly appreciated!

 
Reply With Quote
 
 
 
 
D
Guest
Posts: n/a
 
      06-01-2006
Thanks, Jean-Paul - is there any way to do it without using Twisted,
since I am not very familiar with it? (i.e. just using the os library)
Thanks.

Jean-Paul Calderone wrote:
> On 1 Jun 2006 07:34:23 -0700, D <(E-Mail Removed)> wrote:
> >Hello, I need to write a server program that performs the following
> >tasks:
> >
> >1) Listens on TCP port 5555 for a connection
> >2) When client connects, launches application (for example, vi), then
> >closes connection with client
> >3) Goes back to listening on TCP port 5555 for an incoming connection

>
> Untested:
>
> from twisted.internet import protocol, reactor
>
> class ViRunner(protocol.Protocol):
> def connectionMade(self):
> reactor.spawnProcess(
> None,
> '/usr/bin/setsid',
> ['setsid', '/usr/bin/vi'])
> self.transport.loseConnection()
>
> f = protocol.ServerFactory()
> f.protocol = ViRunner
> reactor.listenTCP(5555, f)
> reactor.run()
>
> Jean-Paul


 
Reply With Quote
 
 
 
 
Carl
Guest
Posts: n/a
 
      06-01-2006
D wrote:

> Thanks, Jean-Paul - is there any way to do it without using Twisted,
> since I am not very familiar with it? (i.e. just using the os library)
> Thanks.
>
> Jean-Paul Calderone wrote:
>> On 1 Jun 2006 07:34:23 -0700, D <(E-Mail Removed)> wrote:
>> >Hello, I need to write a server program that performs the following
>> >tasks:
>> >
>> >1) Listens on TCP port 5555 for a connection
>> >2) When client connects, launches application (for example, vi), then
>> >closes connection with client
>> >3) Goes back to listening on TCP port 5555 for an incoming connection

>>
>> Untested:
>>
>> from twisted.internet import protocol, reactor
>>
>> class ViRunner(protocol.Protocol):
>> def connectionMade(self):
>> reactor.spawnProcess(
>> None,
>> '/usr/bin/setsid',
>> ['setsid', '/usr/bin/vi'])
>> self.transport.loseConnection()
>>
>> f = protocol.ServerFactory()
>> f.protocol = ViRunner
>> reactor.listenTCP(5555, f)
>> reactor.run()
>>
>> Jean-Paul


Use import socket ifyou don't want to use twisted (which is incredibly
good). Google for "+socket +python +server" and you will find what you are
looking for.

See, for example,
http://floppsie.comp.glam.ac.uk/Glam...ireless/5.html

Carl
 
Reply With Quote
 
D
Guest
Posts: n/a
 
      06-01-2006
Sorry, I should've specified - I'm familiar with sockets, but I was
referring to spawning a 'vi' process independent of my Python app..


Carl wrote:
> D wrote:
>
> > Thanks, Jean-Paul - is there any way to do it without using Twisted,
> > since I am not very familiar with it? (i.e. just using the os library)
> > Thanks.
> >
> > Jean-Paul Calderone wrote:
> >> On 1 Jun 2006 07:34:23 -0700, D <(E-Mail Removed)> wrote:
> >> >Hello, I need to write a server program that performs the following
> >> >tasks:
> >> >
> >> >1) Listens on TCP port 5555 for a connection
> >> >2) When client connects, launches application (for example, vi), then
> >> >closes connection with client
> >> >3) Goes back to listening on TCP port 5555 for an incoming connection
> >>
> >> Untested:
> >>
> >> from twisted.internet import protocol, reactor
> >>
> >> class ViRunner(protocol.Protocol):
> >> def connectionMade(self):
> >> reactor.spawnProcess(
> >> None,
> >> '/usr/bin/setsid',
> >> ['setsid', '/usr/bin/vi'])
> >> self.transport.loseConnection()
> >>
> >> f = protocol.ServerFactory()
> >> f.protocol = ViRunner
> >> reactor.listenTCP(5555, f)
> >> reactor.run()
> >>
> >> Jean-Paul

>
> Use import socket ifyou don't want to use twisted (which is incredibly
> good). Google for "+socket +python +server" and you will find what you are
> looking for.
>
> See, for example,
> http://floppsie.comp.glam.ac.uk/Glam...ireless/5.html
>
> Carl


 
Reply With Quote
 
D
Guest
Posts: n/a
 
      06-05-2006
Sorry to bring it back up, but is there a way to spawn the process
without Twisted?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C++ 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui C Programming 0 04-27-2009 12:51 PM
3 ESSENTIAL TOOLS FOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLSFOR STARTING AND MAINTAINING...3 ESSENTIAL TOOLS FOR STARTING ANDMAINTAINING... Oanh Bui Python 0 04-27-2009 12:46 PM
How do I get the process id when starting a process using os.popen2 or os.popen3 on linux? mikem76@gmail.com Python 1 06-07-2006 10:27 PM
Starting a new Process under a Specified Windows Account =?Utf-8?B?Q2hyaXN0b3BoZXI=?= ASP .Net 3 01-03-2005 07:43 PM



Advertisments