Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed Mar 20, 2013 9:04 am 
Offline
Senior Newbie

Joined: Mon Dec 26, 2011 8:24 pm
Posts: 17
I have two python scripts for a socket server one of them just servers a policy file the other one is the actual server.

I run them as root from shell like so :

>python policyServer.py > log1.txt &
>python socketServer.py > log2.txt &


Then my flash client can connect and communicate with the sockeServer just fine.

After I left those two python apps running over night and came back this morning both of them were gone from the "top" and the flash client was no longer working.
The python scripts are using non-blocking sockets and just have something like (pseudocode):

Code:
while True:

    ready_to_read, ready_to_write, in_error = select.select(changed_sockets,[],[])
         
    for s in ready_to_read:
       s.read()


Is there a limit to the time a python app can run? Or is something in Linode's system killing scripts that are running for a long time? I want these scripts to run as long as my Linode is running.


Edit found some code that would prevent the scripts from receiving hang up signals going to try with this and see if they still get killed :

Code:
nohup python policyServer.py > policyLog.txt &
nohup python simpleServer.py > simpleServerLog.txt &


Last edited by Finglor on Wed Mar 20, 2013 9:25 am, edited 1 time in total.

Top
   
PostPosted: Wed Mar 20, 2013 9:20 am 
Offline
Senior Member
User avatar

Joined: Sat Oct 16, 2004 11:13 am
Posts: 176
It's definitely not Linode. Have you checked the kernel logs, etc., in case you ran out of ram and the kernel killed the process?


Top
   
PostPosted: Wed Mar 20, 2013 9:27 am 
Offline
Senior Newbie

Joined: Mon Dec 26, 2011 8:24 pm
Posts: 17
No I haven't but I highly doubt that's the problem, memory usage is steady at 150mb there are no users except me. Going to try with `nohup python server.py &` and see if it makes a difference.


Top
   
PostPosted: Wed Mar 20, 2013 10:17 am 
Offline
Senior Member
User avatar

Joined: Wed Mar 17, 2004 4:11 pm
Posts: 554
Website: http://www.unixtastic.com
Location: Europe
Finglor wrote:
No I haven't but I highly doubt that's the problem, memory usage is steady at 150mb there are no users except me. Going to try with `nohup python server.py &` and see if it makes a difference.


You are assuming. Assumption is the mother of all fuck-ups.

Nohup only catches hup signals, it would be better to trap signals in your process. My guess is this is either an OOM event or your processes dying due to an internal error.


Top
   
PostPosted: Wed Mar 20, 2013 1:13 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
If the process was started from a command line, and then left running in the background and then the shell logged out (timed out; NAT connection from home router closed etc etc) then it's possible that nohup will keep the process running. But that would show the python program isn't properly designed to run as a daemon.

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
PostPosted: Wed Mar 20, 2013 2:21 pm 
Offline
Senior Newbie

Joined: Mon Dec 26, 2011 8:24 pm
Posts: 17
Do you guys have some sources that I can read to make it a proper daemon that always runs in the background?

Right now I create a init script and it runs those 2 python scripts at system boot followed this guide :

http://www.debian-administration.org/articles/28


Is there some stuff I need to do in my python app too? How do I trap signals in my python app etc.?


Top
   
PostPosted: Wed Mar 20, 2013 4:36 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
If I was doing it in C then I'd look at "man 3 daemon"

_________________
Rgds

Stephen

(Linux user since kernel version 0.11)


Top
   
PostPosted: Wed Mar 20, 2013 8:40 pm 
Offline
Senior Member

Joined: Sat May 03, 2008 4:01 pm
Posts: 569
Website: http://www.mattnordhoff.com/
Finglor wrote:
I run them as root from shell like so :

As root!? Whyyy? :(

If they absolutely have to be root to bind a low port, at least drop privileges afterwards.

_________________
Matt Nordhoff (aka Peng on IRC)


Top
   
PostPosted: Thu Mar 21, 2013 3:52 am 
Offline
Senior Member
User avatar

Joined: Wed Mar 17, 2004 4:11 pm
Posts: 554
Website: http://www.unixtastic.com
Location: Europe
Finglor wrote:
Do you guys have some sources that I can read to make it a proper daemon that always runs in the background?


This looks like what you want:
https://pypi.python.org/pypi/python-daemon/

You should work on your google-fu.


Top
   
PostPosted: Thu Mar 21, 2013 10:27 am 
Offline
Senior Newbie

Joined: Mon Dec 26, 2011 8:24 pm
Posts: 17
Haha thanks guys, there is no need for it to run under root so I will just run it as a regular user, it binds to port 9999.

I will check this python-deamon thing out.

Thank you.


Top
   
PostPosted: Fri Mar 22, 2013 3:14 am 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
You may also want to check out monit (probably available in your distro's repositories). It periodically checks if configured services are available and, if not, can alert you or attempt to restart the service itself.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group