pyminer/pkgs/socket_server/index.html
2021-03-19 19:44:54 +08:00

469 lines
18 KiB
HTML
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="zh_CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Socket数据服务器 &#8212; pyminer 文档</title>
<link href="../../_static/css/theme.css" rel="stylesheet" />
<link href="../../_static/css/index.101715efdecc9b59cb6e1ddfa685c31f.css" rel="stylesheet" />
<link rel="stylesheet"
href="../../_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="../../_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="../../_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/pyminer.css" type="text/css" />
<link rel="preload" as="script" href="../../_static/js/index.d8bbf5861d671d414e1a.js">
<script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/translations.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="索引" href="../../genindex.html" />
<link rel="search" title="搜索" href="../../search.html" />
<link rel="next" title="pyminer2.extensions.packages.socket_server.main" href="main.html" />
<link rel="prev" title="pyminer2.extensions.packages.setting_manager.ui_inputs" href="../setting_manager/ui_inputs.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<nav class="navbar navbar-light navbar-expand-lg bg-light fixed-top bd-navbar" id="navbar-main"><div class="container-xl">
<a class="navbar-brand" href="../../contents.html">
<p class="title">pyminer</p>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-menu" aria-controls="navbar-menu" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar-menu" class="col-lg-9 collapse navbar-collapse">
<ul id="navbar-main-elements" class="navbar-nav mr-auto">
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="../../pyminer/index.html">
主程序部分
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="../../pmg/index.html">
界面部分
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="../../alg/index.html">
算法部分
</a>
</li>
<li class="toctree-l1 current active nav-item">
<a class="reference internal nav-link" href="../index.html">
插件部分
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="../../dev/index.html">
开发工具部分
</a>
</li>
<li class="toctree-l1 nav-item">
<a class="reference internal nav-link" href="../../contribute/index.html">
参与贡献
</a>
</li>
</ul>
<ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
</ul>
</div>
</div>
</nav>
<div class="container-xl">
<div class="row">
<!-- Only show if we have sidebars configured, else just a small margin -->
<div class="col-12 col-md-3 bd-sidebar"><form class="bd-search d-flex align-items-center" action="../../search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form>
<nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<ul class="current nav bd-sidenav">
<li class="toctree-l2">
<a class="reference internal" href="../document_server/index.html">
帮助文档服务器
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../drawings_toolbar/index.html">
pyminer2.extensions.packages.drawings_toolbar
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../embedded_browser/index.html">
内嵌浏览器
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../extension_demo/index.html">
pyminer2.extensions.packages.extension_demo
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../file_tree/index.html">
pyminer2.extensions.packages.file_tree
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../graph_agg/index.html">
pyminer2.extensions.packages.graph_agg
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../ipython_console/index.html">
IPython控制台
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../jupyter_notebook_support/index.html">
pyminer2.extensions.packages.jupyter_notebook_support
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../pm_helpLinkEngine/index.html">
pyminer2.extensions.packages.pm_helpLinkEngine
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../pm_marketplace/index.html">
pyminer2.extensions.packages.pm_marketplace
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../pm_modelling/index.html">
pyminer2.extensions.packages.pm_modelling
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../pm_statistics/index.html">
pyminer2.extensions.packages.pm_statistics
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../pmagg/index.html">
PMAgg绘图工具箱
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../qt_vditor/index.html">
pyminer2.extensions.packages.qt_vditor
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../setting_manager/index.html">
pyminer2.extensions.packages.setting_manager
</a>
</li>
<li class="toctree-l2 current active">
<a class="current reference internal" href="#">
Socket数据服务器
</a>
<ul>
<li class="toctree-l3">
<a class="reference internal" href="main.html">
pyminer2.extensions.packages.socket_server.main
</a>
</li>
<li class="toctree-l3">
<a class="reference internal" href="server_by_socket.html">
pyminer2.extensions.packages.socket_server.server_by_socket
</a>
</li>
</ul>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../tool_box/index.html">
pyminer2.extensions.packages.tool_box
</a>
</li>
<li class="toctree-l2">
<a class="reference internal" href="../workspace_inspector/index.html">
pyminer2.extensions.packages.workspace_inspector
</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="d-none d-xl-block col-xl-2 bd-toc">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i> On this page
</div>
<nav id="bd-toc-nav">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#id1">
简介
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#id2">
未来的任务
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#id3">
回调方法列表
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#pickle">
返回pickle形式的变量
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h4 nav-item toc-entry">
<a class="reference internal nav-link" href="#id4">
名称
</a>
</li>
<li class="toc-h4 nav-item toc-entry">
<a class="reference internal nav-link" href="#id5">
输入值
</a>
</li>
<li class="toc-h4 nav-item toc-entry">
<a class="reference internal nav-link" href="#id6">
返回值
</a>
</li>
</ul>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id7">
以pickle形式设置变量
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#pyminer">
获取PyMiner主界面的设置项
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id8">
设置PyMiner的设置项
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id9">
获取PyMiner主界面的样式表
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id10">
获取所有的变量名称
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id11">
获取所有的公共可访问变量的名称
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id12">
以字典的形式一次设置多个变量
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id13">
获取全部公共可访问的变量
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#id14">
删除变量
</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<main class="col-12 col-md-9 col-xl-7 py-md-5 pl-md-5 pr-md-4 bd-content" role="main">
<div>
<div class="section" id="socket">
<h1>Socket数据服务器<a class="headerlink" href="#socket" title="永久链接至标题"></a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="main.html">pyminer2.extensions.packages.socket_server.main</a></li>
<li class="toctree-l1"><a class="reference internal" href="server_by_socket.html">pyminer2.extensions.packages.socket_server.server_by_socket</a></li>
</ul>
</div>
<span class="target" id="module-pyminer2.extensions.packages.socket_server"></span><p>数据服务器基于 <code class="docutils literal notranslate"><span class="pre">PMGWidgets</span></code> 里面的 <code class="docutils literal notranslate"><span class="pre">server</span></code> ,是一个简单的基于 <code class="docutils literal notranslate"><span class="pre">PyQt</span></code> 的连接。</p>
<p>目前的方法:</p>
<div class="section" id="id1">
<h2>简介<a class="headerlink" href="#id1" title="永久链接至标题"></a></h2>
<p>数据服务器之前考虑过用共享内存的方式,但是后来,&#64;Reco由于时间原因暂时搁置了这块开发任务
所以暂时用socket的tcp传输顶上。</p>
<p>这个数据服务器就是socket-server插件。它需要调用PyMiner的插件接口借以访问和修改工作空间的数据。
至于端口号目前还是写死的——12306。这一点之后应该也需要克服。</p>
<p><strong>[TODO]:之后还需要增加端口选择的功能!</strong></p>
<p>服务器的主代码定义在插件中当然还有一个服务器基类定义在pmgwidgets里面。大致的工作原理是</p>
<p>#. 服务器启动用一个QThread开始监听套接字。
<strong>为什么不用Threading盖因Qt的界面与其不兼容。使用起来可能导致程序崩溃。</strong>
#. 服务器收到连接请求。请求分为两种若为“long_conn”则开启一个新线程维护一个长连接
在连接中回复一条确认报文;对于其他请求则直接回复一个确认报文。
#. 对于2中的前一种情况长连接需要监听同一个端口发送过来的事件。当没有收到消息的时候自然就是挂起的。
#. 对于2中的第二种情况服务器直接用前台线程进行处理并且发送回相应信息。
#. 除了以上长连接和短连接服务器每10秒发送一个心跳广播如果发现端口断连就将其踢下去。
<strong>注意:针对踢下线这一点,目前还没有重连机制。</strong>
#. 广播的报文内容不只是心跳保活。如工作空间数据发生变化时会发送一条这样的报文:</p>
<p>“{name: broadcast, message: data_changed, data_name: a, data_source: ipython}”</p>
<p>事实上报文解析的方式已经预定义好了就在pyminer_algorithm类里面有get_var和set_var方法
可以直接访问或者修改工作空间中的变量。</p>
<p>对于心跳包的接收定义在pmgwidgets里面。如果是普通的程序可以用GeneralClient;
基于Threading如果是想要嵌入其他PyQt程序就用PMClient(基于QThread)。</p>
<p><strong>未来相应的接口可以而且应该整合到统一的接口pip包中</strong></p>
</div>
<div class="section" id="id2">
<h2>未来的任务<a class="headerlink" href="#id2" title="永久链接至标题"></a></h2>
<p>1、尽量减少用pickle传递数据</p>
<p>比如说对于可用json传递的数据可以考虑用json进行传递。这样也可以方便解析。</p>
<p>如果要这样做,那么就能增强程序的通用性。</p>
<p>目前用debug在pandas等程序的编码和解码方面还是不尽如人意。</p>
<p>比如说set_var函数可否增加一个属性比如说 <code class="docutils literal notranslate"><span class="pre">method='json'</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">method='pickle'</span></code> ?</p>
<p>2、metadata的概念需要用起来。</p>
<p>什么叫数据的metadata?如何使用?</p>
<p>3、注意线程安全性</p>
</div>
<div class="section" id="id3">
<h2>回调方法列表<a class="headerlink" href="#id3" title="永久链接至标题"></a></h2>
<div class="section" id="pickle">
<h3>返回pickle形式的变量<a class="headerlink" href="#pickle" title="永久链接至标题"></a></h3>
<div class="section" id="id4">
<h4>名称<a class="headerlink" href="#id4" title="永久链接至标题"></a></h4>
<p><code class="docutils literal notranslate"><span class="pre">self.read_pickle_data</span></code></p>
</div>
<div class="section" id="id5">
<h4>输入值<a class="headerlink" href="#id5" title="永久链接至标题"></a></h4>
<p></p>
</div>
<div class="section" id="id6">
<h4>返回值<a class="headerlink" href="#id6" title="永久链接至标题"></a></h4>
<p><code class="docutils literal notranslate"><span class="pre">{'message':</span> <span class="pre">'succeeded',</span> <span class="pre">'var_dic':</span> <span class="pre">data_b64}</span></code></p>
</div>
</div>
<div class="section" id="id7">
<h3>以pickle形式设置变量<a class="headerlink" href="#id7" title="永久链接至标题"></a></h3>
<p>write_p: self.set_pickle_data,</p>
</div>
<div class="section" id="pyminer">
<h3>获取PyMiner主界面的设置项<a class="headerlink" href="#pyminer" title="永久链接至标题"></a></h3>
<p>get_settings: self.get_settings,</p>
</div>
<div class="section" id="id8">
<h3>设置PyMiner的设置项<a class="headerlink" href="#id8" title="永久链接至标题"></a></h3>
<p>set_settings_param: self.set_settings_param</p>
</div>
<div class="section" id="id9">
<h3>获取PyMiner主界面的样式表<a class="headerlink" href="#id9" title="永久链接至标题"></a></h3>
<p>get_style_sheet: self.get_style_sheet</p>
</div>
<div class="section" id="id10">
<h3>获取所有的变量名称<a class="headerlink" href="#id10" title="永久链接至标题"></a></h3>
<p>get_all_variable_names: self.get_all_data_names</p>
</div>
<div class="section" id="id11">
<h3>获取所有的公共可访问变量的名称<a class="headerlink" href="#id11" title="永久链接至标题"></a></h3>
<p>get_all_public_variable_names: self.get_all_public_data_names</p>
</div>
<div class="section" id="id12">
<h3>以字典的形式一次设置多个变量<a class="headerlink" href="#id12" title="永久链接至标题"></a></h3>
<p>write_var_dic: self.update_pickle_data_dict</p>
</div>
<div class="section" id="id13">
<h3>获取全部公共可访问的变量<a class="headerlink" href="#id13" title="永久链接至标题"></a></h3>
<p>get_var_dic: self.get_var_dic</p>
</div>
<div class="section" id="id14">
<h3>删除变量<a class="headerlink" href="#id14" title="永久链接至标题"></a></h3>
<p>delete_variable: self.delete_variable</p>
</div>
</div>
</div>
</div>
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="../setting_manager/ui_inputs.html" title="previous page">pyminer2.extensions.packages.setting_manager.ui_inputs</a>
<a class='right-next' id="next-link" href="main.html" title="next page">pyminer2.extensions.packages.socket_server.main</a>
</div>
</main>
</div>
</div>
<script src="../../_static/js/index.d8bbf5861d671d414e1a.js"></script>
<footer class="footer mt-5 mt-md-0">
<div class="container">
<p>
&copy; Copyright 2020, py2cn.<br/>
<a href="http://sphinx-doc.org/">Sphinx</a> 3.4.0+ 创建。<br/>
</p>
</div>
</footer>
</body>
</html>