[Tutor] running a game server

Alan Gauld alan.gauld at yahoo.co.uk
Sun Jan 6 13:09:10 EST 2019


On 06/01/2019 14:14, nathan tech wrote:

> My question is, is python really the way to go for game servers?

Its certainly one possibility. Without a lot more details about
the design, expected load, OS etc its impossible to say with any certainty.


> I remember, long ago, running a script that went along the lines of:
> 
>      import shutil
>      import time
> 
>      while 1:
>       f=open("backup.count_file.txt","r");
>       num=int(f.read())
>       f.close()
> 
>       f=open("backup/count_file.txt","w");
>       f.write(str(num+1));
>       f.close()
> 
>       shutil.copy("my_file.txt", "my_file.txt.backup."+str(num))
>       time.sleep(900)
> 
> 
> After running for a day, this had to be killed because it sucked up more 
> memory than anything I'd ever seen before.

It's impossible to debug code that may or may not be the
same as that shown. But there is certainly nothing in the
code above that should eat memory. That having been said
opening and closing the file like that is probably not
the most efficient way of doing things. But for a test
its probably OK.

> I don't mind too much if its using a bit of memory, but, if python is 
> just going to leak all over the place and I'm better off learning c or c 
> sharp or something, then I'd like to know!

Python certainly doesn't "leak all over the place" and
is used for many industrial strength servers that run
for months at a time. But if you don't clean up properly
it can, of course, leak.

If you can find the actual code you used and tell us the
Python version and OS we might spot the problem. Otherwise
I can only reiterate that Python might be suitable depending
on your exact requirements.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list