Aşağıda Windows ortamında Python geliştiricileri için kritik komut setleri, servis olarak Python çalıştırma, Task Scheduler (zamanlayıcı) kullanımı ve uzaktan yönetim senaryoları ile birlikte kurumsal düzeyde bir operasyon rehberi bulacaksın. Anlatım, üretim ortamı düşünülerek hazırlanmıştır.
1. Windows CMD ve PowerShell Python Komut Seti
1.1 Python Çalıştırma ve Versiyon Yönetimi
CMD
python --version
python -V
py --version
Python interpreter başlatma
python
Script çalıştırma
python app.py
Belirli versiyon çalıştırma
py -3.11 app.py
py -3.10 app.py
1.2 Paket Yönetimi (pip)
pip --version
pip install requests
pip install flask==3.0.0
pip list
pip freeze > requirements.txt
pip install -r requirements.txt
pip uninstall requests
1.3 Sanal Ortam (Virtual Environment)
Oluşturma
python -m venv venv
Aktifleştirme (CMD)
venv\Scripts\activate
PowerShell
venv\Scripts\Activate.ps1
Deactivate
deactivate
2. Windows Servisi Olarak Python Çalıştırma
Kurumsal sistemlerde Python script’leri genelde servis olarak çalışır.
2.1 En Basit Yöntem: NSSM (Önerilen)
NSSM (Non-Sucking Service Manager)
Kurulum sonrası servis oluşturma:
nssm install MyPythonService
Açılan GUI’de:
-
Path:
C:\Python311\python.exe -
Arguments:
C:\app\main.py -
Startup directory:
C:\app
Servisi başlatma
nssm start MyPythonService
Servisi durdurma
nssm stop MyPythonService
2.2 SC (Windows Native Service) ile
Direkt Python servis yapmak zor ve sınırlıdır ama wrapper ile mümkündür.
sc create MyPythonService binPath= "C:\Python311\python.exe C:\app\main.py"
Başlatma:
sc start MyPythonService
Silme:
sc delete MyPythonService
2.3 Python'u servis gibi yönetmek için production pattern
Kurumsal yaklaşım:
python.exe-
uvicorn(FastAPI) -
gunicorn(Linux ağırlıklı ama WSL ile kullanılabilir) -
waitress(Windows için güçlü)
Örnek:
pip install waitress
waitress-serve --port=8080 app:app
3. Windows Task Scheduler (Zamanlanmış Python Çalıştırma)
3.1 GUI ile Task Oluşturma
Adımlar:
- Task Scheduler aç
- “Create Basic Task”
- Trigger:
-
Daily / Hourly / At logon
- Action:
-
Start a Program
- Program:
C:\Python311\python.exe
- Arguments:
C:\app\script.py
3.2 CMD ile Task Oluşturma
Günlük çalıştırma
schtasks /create /tn "PythonJob" /tr "C:\Python311\python.exe C:\app\script.py" /sc daily /st 10:00
Her 5 dakikada bir çalıştırma
schtasks /create /tn "PythonJob" /tr "C:\Python311\python.exe C:\app\script.py" /sc minute /mo 5
Sistemde login olunca çalıştırma
schtasks /create /tn "PythonStartup" /tr "C:\Python311\python.exe C:\app\script.py" /sc onlogon
Task silme
schtasks /delete /tn "PythonJob" /f
Task listeleme
schtasks /query /fo LIST
4. Loglama ve Kurumsal Çalışma Modeli
Python log örneği (kritik)
import logging
logging.basicConfig(
filename="app.log",
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s"
)
logging.info("Service started")
5. Uzaktan SSH ile Windows Server Yönetimi
Windows’ta OpenSSH kullanılır.
SSH bağlanma
ssh user@192.168.1.10
Key ile bağlanma
ssh -i key.pem user@server-ip
Python remote deploy pattern
scp app.py user@server:/app/
6. Windows’ta Background Process Yönetimi
PowerShell ile arka planda çalıştırma
Start-Process python -ArgumentList "C:\app\script.py" -WindowStyle Hidden
Process kontrol
tasklist | findstr python
Kill process
taskkill /IM python.exe /F
7. Kurumsal Mimari Önerisi (Best Practice)
Bir eğitim perspektifiyle gerçek üretim standardı:
Katmanlı yapı
- Scheduler (Task Scheduler / Cron benzeri)
- Service Layer (NSSM / Waitress / FastAPI)
- Worker Layer (Python scripts)
- Logging Layer (file + ELK)
Önerilen model
- API: FastAPI
- Worker: Celery + Redis
- Scheduler: Task Scheduler veya Celery Beat
- Service: NSSM wrapper
8. İleri Seviye: Python’u Windows Servis Mimarisi Olarak Tasarlamak
Örnek servis script yapısı
import time
def run():
while True:
print("Service running...")
time.sleep(10)
if __name__ == "__main__":
run()
9. Özet Kurumsal Komut Seti
| Amaç | Komut |
|---|---|
| Python çalıştır | python app.py |
| Paket kur | pip install flask |
| Venv | python -m venv venv |
| Task oluştur | schtasks /create |
| Servis (NSSM) | nssm install |
| Process kontrol | tasklist |
| Kill process | taskkill |
| SSH | ssh user@ip |
Top comments (0)