-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiprocess.py
65 lines (58 loc) · 1.73 KB
/
multiprocess.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import multiprocessing
import random
import urllib
import re
import yaml
class NeetsDaemon(object):
def __init__(self, processes):
self.processes = processes
self.queue = multiprocessing.Queue()
def start(self):
for i in range(self.processes):
# 新しいプロセスを作る
p = multiprocessing.Process(target=self._child_main_loop,
args=(self.queue, ))
# デーモンフラグを有効にすると親プロセスが死んだとき一緒に死ぬようになる
p.daemon = True
# プロセスを開始する
p.start()
# 自分もメインループに入る
self._parent_main_loop()
# 親プロセスのループ
def _parent_main_loop(self):
while True:
print self.queue.get()
# 子プロセスのループ
def _child_main_loop(self, queue):
while True:
url = "http://geekhost.net/OK"
f = urllib.urlopen(url)
data = f.read()
#print data
abcPattern = re.compile(r'OK')
if abcPattern.match(data):
queue.put('Already logined')
else:
queue.put('Need login')
LOGIN_URL = 'https://auth-wlc.ntwk.dendai.ac.jp/login.html'
#LOGIN_URL = 'http://geekhost.net/checkparams.php'
pd = yaml.load(open('config.yaml').read().decode('utf-8'))
pd['buttonClicked'] = '4'
pd['redirect_url'] = 'http://google.com/'
pd["err_flag"] = "0"
pd["err_msg"] = ""
pd["info_flag"] = "0"
pd["info_msg"] = ""
params = urllib.urlencode(pd)
print repr(params)
up = urllib.urlopen(LOGIN_URL, params)
# あとは寝てる
time.sleep(yaml.load(open('config.yaml').read().decode('utf-8'))['threadtime'])
if __name__ == '__main__':
neetsd = NeetsDaemon(1)
# デーモンを開始する
neetsd.start()