First stab at tackling issues involved in running Syndicate in a multi-threaded context
This commit is contained in:
parent
2b5a0cdf02
commit
c0afd99e46
|
@ -12,11 +12,14 @@ def __setup():
|
|||
class turn:
|
||||
@staticproperty
|
||||
def active():
|
||||
return _active.turn
|
||||
t = getattr(_active, 'turn', False)
|
||||
if t is False:
|
||||
t = _active.turn = None
|
||||
return t
|
||||
|
||||
@staticproperty
|
||||
def log():
|
||||
return _active.turn.log
|
||||
return turn.active.log
|
||||
|
||||
def run(facet, action):
|
||||
Turn.run(facet, action)
|
||||
|
@ -25,11 +28,11 @@ def __setup():
|
|||
Turn.external(facet, action, loop=loop)
|
||||
|
||||
def active_facet():
|
||||
return _active.turn._facet
|
||||
return turn.active._facet
|
||||
|
||||
def install_definition(name, definition):
|
||||
def handler(*args, **kwargs):
|
||||
return definition(_active.turn, *args, **kwargs)
|
||||
return definition(turn.active, *args, **kwargs)
|
||||
setattr(turn, name, handler)
|
||||
|
||||
for (name, definition) in Turn.__dict__.items():
|
||||
|
|
|
@ -284,7 +284,10 @@ def queue_task_threadsafe(thunk, loop = None):
|
|||
class Turn:
|
||||
@staticproperty
|
||||
def active():
|
||||
return _active.turn
|
||||
t = getattr(_active, 'turn', False)
|
||||
if t is False:
|
||||
t = _active.turn = None
|
||||
return t
|
||||
|
||||
@classmethod
|
||||
def run(cls, facet, action, zombie_turn = False):
|
||||
|
@ -551,7 +554,11 @@ def __boot_inert():
|
|||
async def __run_inert():
|
||||
Actor(__boot_inert, name = '_inert_actor')
|
||||
def __setup_inert():
|
||||
loop = asyncio.new_event_loop()
|
||||
loop.run_until_complete(__run_inert())
|
||||
loop.close()
|
||||
def setup_main():
|
||||
loop = asyncio.new_event_loop()
|
||||
loop.run_until_complete(__run_inert())
|
||||
loop.close()
|
||||
t = threading.Thread(target=setup_main)
|
||||
t.start()
|
||||
t.join()
|
||||
__setup_inert()
|
||||
|
|
Loading…
Reference in New Issue