0
from bin import pmGetter
from threading import Thread
import time
possibleRequests = ['test', 'test1']
inbox = []
inbox = pmGetter.getPms()
# time to do threading
def pmGetterLoop():
while True:
inbox = pmGetter.getPms()
def inboxReader():
print('triggered')
while True:
tempInbox = []
tempInbox = inbox.inboxMessage #inboxMesage remains filled?
print(inbox.inboxMessage)
i = 0
while (i < len(tempInbox)):
if (tempInbox[i] in possibleRequests):
print('THIS IS WORKING')
#print(i)
i+=1
time.sleep(2)
def commandBreaker(commandString):
return commandString.split(',')
threadOne = Thread(target=pmGetterLoop)
threadTwo = Thread(target=inboxReader)
threadTwo.start()
threadOne.start()
#print(commandBreaker('this,is,a,test'))#this is what will be used to split commands
を空にされていない、これは私がこの出力[]なぜ配列はpythonで
[] why?
test
this is a test
triggered
['test', 'this is a test']
THIS IS WORKING
[] why? #this is from getPms.bot_run()
['test', 'this is a test']#this is from def inboxReader
THIS IS WORKING
を得る何らかの理由でメイン
import praw
import time
class getPms():
r = praw.Reddit(user_agent="Test Bot By /u/**********")
r.login(username='******************', password='*************')
cache = []
inboxMessage = []
file = 'cache.txt'
def __init__(self):
self.cache = self.cacheRead(self.file)
self.bot_run()
self.cacheSave(self.file)
time.sleep(2)
#return self.inboxMessage
def bot_run(self):
print(self.inboxMessage, ' why?')
self.inboxMessage = []
inbox = self.r.get_inbox(limit=25)
# print(r.get_friends())#this works
for message in inbox:
if message.id not in self.cache:
#print(message.id)
print(message.body)
# print(message.subject)
self.cache.append(message.id)
self.inboxMessage.append(message.body)
# else:
# print("no messages")
def cacheSave(self, file):
with open(file, 'w') as f:
for s in self.cache:
f.write(s + '\n')
def cacheRead(self, file):
with open(file, 'r') as f:
cache1 = [line.rstrip('\n') for line in f]
return cache1
のですか?ここで[]
それはちょっと、今ここにあるいくつかのねじれ動作しますが、私は –
もう一つの問題は、getPmsが完全にスレッドセーフではないということです、それをうまくすることができ感謝します。あなたはそれを作成するときにロックを使用する必要があります。それ以外の場合、getPmsのインスタンス化が完了する前にスレッド2が受信ボックスにアクセスする可能性があります –