Python Ram Kullanımı ?

Başlatan noktafat, 01 Kasım 2013 - 04:21:16

« önceki - sonraki »

0 Üyeler ve 1 Ziyaretçi konuyu incelemekte.

noktafat

Pythonda ilk programımı yazdım ancak program RAM'den yaklaşık 9.9 MB kullanıyor. Apache ve Mysql server açma kapamada kullanıyorum programı, yani çok işlevleri olan birşeyde değil. Programı güncellemek (örneğin apache kapatıldığında, menüde "Apache Başlat" ın yer almasu) için restart_program diye bir fonksiyon ödünç aldım o da ekstra sys modülünü kullanıyor. Ancak bu fonksiyone gerek olmadığını düşünüyorum, bu konuda önerileriniz ve python kodlama ile ilgili tavsiyeleriniz nelerdir?
Kodlar:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gi.repository import Gtk
import os,commands,sys
class TepsiDugmesi:
def __init__(self,iconname):
self.menu=Gtk.Menu()
APPIND_SUPPORT =1
try: from gi.repository import AppIndicator3
except: APPIND_SUPPORT=0
if APPIND_SUPPORT == 1:
self.ind = AppIndicator3.Indicator.new("help", iconname, AppIndicator3.IndicatorCategory.APPLICATION_STATUS)
self.ind.set_status (AppIndicator3.IndicatorStatus.ACTIVE)
self.ind.set_menu(self.menu)
else:
self.myStatusIcon = Gtk.StatusIcon()
self.myStatusIcon.set_from_icon_name(iconname)
self.myStatusIcon.connect('popup-menu', self.right_click_event_statusicon)

def add_menu_item(self, command, title):
aMenuitem = Gtk.MenuItem()
aMenuitem.set_label(title)
aMenuitem.connect("activate", command)

self.menu.append(aMenuitem)
self.menu.show_all()

def add_seperator(self):
aMenuitem = Gtk.SeparatorMenuItem()
self.menu.append(aMenuitem)
self.menu.show_all()

def get_tray_menu(self):
return self.menu


def right_click_event_statusicon(self, icon, button, time):
self.get_tray_menu()

def pos(menu, aicon):
return (Gtk.StatusIcon.position_menu(menu, aicon))

self.menu.popup(None, None, pos, icon, button, time)
class Islem:
def ProgramKontrol(self,programAdi):
TumUygulamalar=commands.getoutput("ps -A")
if programAdi in TumUygulamalar:
return True
else:
return False
def restart_program(self):
python = sys.executable
os.execl(python, python, * sys.argv)
def ApacheDurdur(self):
os.system("gksudo /etc/init.d/apache2 stop")
self.restart_program()
def ApacheBaslat(self):
os.system("gksudo /etc/init.d/apache2 start")
self.restart_program()
def MysqlBaslat(self):
os.system("gksudo service mysql start")
self.restart_program()
def MysqlDurdur(self):
os.system("gksudo service mysql stop")
self.restart_program()
def ApacheYenile(self):
os.system("gksudo /etc/init.d/apache2 restart")
self.restart_program()
def MysqlYenile(self):
os.system("gksudo service mysql restart")
self.restart_program()
def TumunuBaslat(self):
os.system("gksudo service mysql start && gksudo /etc/init.d/apache2 start")
self.restart_program()
def TumunuDurdur(self):
os.system("gksudo service mysql stop && gksudo /etc/init.d/apache2 stop")
self.restart_program()

def __init__(self):
app = TepsiDugmesi("firefox")
if self.ProgramKontrol("apache2")==True:
app.add_menu_item(lambda x: self.ApacheDurdur(), "Apache Durdur")
app.add_menu_item(lambda x: self.ApacheYenile(), "Apache Yeniden Başlat")
else:
app.add_menu_item(lambda x: self.ApacheBaslat(), "Apache Başlat")
app.add_seperator()
if self.ProgramKontrol("mysqld")==True:
app.add_menu_item(lambda x: self.MysqlDurdur(), "Mysql Durdur")
app.add_menu_item(lambda x: self.MysqlYenile(), "Mysql Yeniden Başlat")
else:
app.add_menu_item(lambda x: self.MysqlBaslat(), "Mysql Başlat")

app.add_seperator()

if self.ProgramKontrol("mysqld")==False and self.ProgramKontrol("apache2")==False:
app.add_menu_item(lambda x: self.TumunuBaslat(), "Tümünü Başlat")
else:
app.add_menu_item(lambda x: self.TumunuDurdur(), "Tümünü Durdur")
app.add_seperator()
app.add_menu_item(lambda x: Gtk.main_quit(), "Çıkış")

if __name__ == '__main__':
Gtk.main()

prog=Islem()