feat(rcf): append hosting back
This commit is contained in:
parent
c137971606
commit
333f0980bf
@ -19,6 +19,7 @@ CONNECT_TIMEOUT = 2
|
||||
WAITING_TIME = 0.001
|
||||
SERVER_MAX = 1
|
||||
|
||||
stop = False
|
||||
|
||||
def zpipe(ctx):
|
||||
"""build inproc pipe for talking to threads
|
||||
@ -161,6 +162,10 @@ class RCFClient(object):
|
||||
"""
|
||||
self.pipe.send_multipart([b"SET", umsgpack.packb(key), umsgpack.packb(value)])
|
||||
|
||||
def exit(self):
|
||||
if self.agent.is_alive():
|
||||
global stop
|
||||
stop = True
|
||||
|
||||
class RCFServer(object):
|
||||
address = None # Server address
|
||||
@ -230,14 +235,16 @@ class RCFClientAgent(object):
|
||||
def rcf_client_agent(ctx, pipe):
|
||||
agent = RCFClientAgent(ctx, pipe)
|
||||
server = None
|
||||
|
||||
global stop
|
||||
while True:
|
||||
if stop:
|
||||
break
|
||||
# logger.info("asdasd")
|
||||
|
||||
poller = zmq.Poller()
|
||||
poller.register(agent.pipe, zmq.POLLIN)
|
||||
server_socket = None
|
||||
|
||||
|
||||
if agent.state == State.INITIAL:
|
||||
server = agent.server
|
||||
if agent.server:
|
||||
@ -255,7 +262,7 @@ def rcf_client_agent(ctx, pipe):
|
||||
poller.register(server_socket, zmq.POLLIN)
|
||||
|
||||
try:
|
||||
items = dict(poller.poll())
|
||||
items = dict(poller.poll(1))
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -277,6 +284,9 @@ def rcf_client_agent(ctx, pipe):
|
||||
logging.info("I: received from {}:{},{} {}".format(server.address,rcfmsg.body.id, server.port, action))
|
||||
else:
|
||||
logger.info("IDLE")
|
||||
|
||||
logger.info("exit thread")
|
||||
stop = False
|
||||
# else: else
|
||||
# agent.state = State.INITIAL
|
||||
|
||||
|
@ -5,11 +5,12 @@ import time
|
||||
import asyncio
|
||||
import queue
|
||||
from operator import itemgetter
|
||||
|
||||
import subprocess
|
||||
import uuid
|
||||
import bgl
|
||||
import blf
|
||||
import bpy
|
||||
import os
|
||||
import gpu
|
||||
import mathutils
|
||||
from bpy_extras import view3d_utils
|
||||
@ -685,7 +686,6 @@ class session_join(bpy.types.Operator):
|
||||
|
||||
client = net_components.RCFClient()
|
||||
client.connect("127.0.0.1",5555)
|
||||
client.set('key', 1)
|
||||
|
||||
|
||||
# net_settings.is_running = True
|
||||
@ -770,13 +770,13 @@ class session_create(bpy.types.Operator):
|
||||
global server
|
||||
global client
|
||||
|
||||
server = net_components.RCFServerAgent()
|
||||
server = subprocess.Popen(['python','server.py'], shell=False, stdout=subprocess.PIPE)
|
||||
time.sleep(0.1)
|
||||
|
||||
bpy.ops.session.join()
|
||||
|
||||
if context.scene.session_settings.init_scene:
|
||||
init_scene()
|
||||
# if context.scene.session_settings.init_scene:
|
||||
# init_scene()
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
@ -798,17 +798,17 @@ class session_stop(bpy.types.Operator):
|
||||
net_settings = context.scene.session_settings
|
||||
|
||||
if server:
|
||||
server.stop()
|
||||
server.kill()
|
||||
del server
|
||||
server = None
|
||||
if client:
|
||||
client.stop()
|
||||
client.exit()
|
||||
del client
|
||||
client = None
|
||||
bpy.ops.asyncio.stop()
|
||||
# bpy.ops.asyncio.stop()
|
||||
net_settings.is_running = False
|
||||
|
||||
unregister_ticks()
|
||||
# unregister_ticks()
|
||||
else:
|
||||
logger.debug("No server/client running.")
|
||||
|
||||
@ -969,17 +969,17 @@ def register():
|
||||
bpy.types.ID.is_updating = bpy.props.BoolProperty(default=False)
|
||||
bpy.types.Scene.session_settings = bpy.props.PointerProperty(
|
||||
type=session_settings)
|
||||
bpy.app.handlers.depsgraph_update_post.append(depsgraph_update)
|
||||
# bpy.app.handlers.depsgraph_update_post.append(depsgraph_update)
|
||||
|
||||
|
||||
def unregister():
|
||||
global server
|
||||
global client
|
||||
|
||||
try:
|
||||
bpy.app.handlers.depsgraph_update_post.remove(depsgraph_update)
|
||||
except:
|
||||
pass
|
||||
# try:
|
||||
# bpy.app.handlers.depsgraph_update_post.remove(depsgraph_update)
|
||||
# except:
|
||||
# pass
|
||||
|
||||
if server:
|
||||
# server.stop()
|
||||
|
20
net_ui.py
20
net_ui.py
@ -55,17 +55,17 @@ class SessionSettingsPanel(bpy.types.Panel):
|
||||
row = layout.row()
|
||||
row.operator("session.join", text="CONNECT")
|
||||
|
||||
# else:
|
||||
else:
|
||||
|
||||
# if net_operators.client.status is net_components.RCFStatus.CONNECTED:
|
||||
# row.label(text="Net frequency:")
|
||||
# row.prop(net_settings, "update_frequency", text="")
|
||||
# row = layout.row()
|
||||
# row.operator("session.stop", icon='QUIT', text="Exit")
|
||||
# elif net_operators.client.status is net_components.RCFStatus.CONNECTING:
|
||||
# row.label(text="connecting...")
|
||||
# row = layout.row()
|
||||
# row.operator("session.stop", icon='QUIT', text="CANCEL")
|
||||
if net_operators.client.agent.is_alive():
|
||||
row.label(text="Net frequency:")
|
||||
row.prop(net_settings, "update_frequency", text="")
|
||||
row = layout.row()
|
||||
row.operator("session.stop", icon='QUIT', text="Exit")
|
||||
# elif net_operators.client.status is net_components.RCFStatus.CONNECTING:
|
||||
# row.label(text="connecting...")
|
||||
# row = layout.row()
|
||||
# row.operator("session.stop", icon='QUIT', text="CANCEL")
|
||||
|
||||
row = layout.row()
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
import collections
|
||||
import logging
|
||||
import threading
|
||||
from uuid import uuid4
|
||||
import binascii
|
||||
import os
|
||||
from random import randint
|
||||
import time
|
||||
from enum import Enum
|
||||
|
||||
from libs import umsgpack, zmq
|
||||
from net_components import RCFMessage
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
CONNECT_TIMEOUT = 2
|
||||
WAITING_TIME = 0.001
|
||||
SERVER_MAX = 1
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user