here is a mutex for events_for_ui:
threads and main thread won't conflict
This commit is contained in:
parent
bd7d629140
commit
c61c33765f
|
@ -140,9 +140,13 @@ class Connection:
|
|||
gajim.config.set('usegpg', False)
|
||||
# END __init__
|
||||
|
||||
def put_event(self, ev):
|
||||
gajim.events_for_ui[self.name].append(ev)
|
||||
|
||||
def dispatch(self, event, data):
|
||||
'''always passes account name as first param'''
|
||||
gajim.events_for_ui[self.name].append([event, data])
|
||||
gajim.mutex_events_for_ui.lock(self.put_event, [event, data])
|
||||
gajim.mutex_events_for_ui.unlock()
|
||||
|
||||
def add_sha(self, p):
|
||||
c = p.setTag('x', namespace = common.xmpp.NS_VCARD_UPDATE)
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
import os
|
||||
import logging
|
||||
import mutex
|
||||
|
||||
import common.config
|
||||
import common.logger
|
||||
|
||||
|
@ -63,8 +65,10 @@ sleeper_state = {} # whether we pass auto away / xa or not
|
|||
#'autoaway': autoaway and use sleeper
|
||||
#'autoxa': autoxa and use sleeper
|
||||
status_before_autoaway = {}
|
||||
#queues of events from connections
|
||||
#queues of events from connections...
|
||||
events_for_ui = {}
|
||||
#... and its mutex
|
||||
mutex_events_for_ui = mutex.mutex()
|
||||
|
||||
socks5quue = None
|
||||
|
||||
|
|
|
@ -999,6 +999,10 @@ class Interface:
|
|||
'HTTP_AUTH': self.handle_event_http_auth,
|
||||
}
|
||||
|
||||
def exec_event(self, account):
|
||||
ev = gajim.events_for_ui[account].pop(0)
|
||||
self.handlers[ev[0]](account, ev[1])
|
||||
|
||||
def process_connections(self):
|
||||
try:
|
||||
# We copy the list of connections because one can disappear while we
|
||||
|
@ -1012,8 +1016,8 @@ class Interface:
|
|||
if gajim.socks5queue.connected:
|
||||
gajim.socks5queue.process(0.01)
|
||||
while len(gajim.events_for_ui[account]):
|
||||
ev = gajim.events_for_ui[account].pop(0)
|
||||
self.handlers[ev[0]](account, ev[1])
|
||||
gajim.mutex_events_for_ui.lock(self.exec_event, account)
|
||||
gajim.mutex_events_for_ui.unlock()
|
||||
time.sleep(0.01) # so threads in connection.py have time to run
|
||||
return True # renew timeout (loop for ever)
|
||||
except KeyboardInterrupt:
|
||||
|
|
Loading…
Reference in New Issue