-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
561 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.. _examples: | ||
|
||
Examples | ||
======== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
examples/client_example.rst | ||
examples/server_example.rst | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
Client Example | ||
============== | ||
|
||
.. code-block:: python | ||
import logging | ||
from stiqueue.sqclient import SQClient | ||
class SQClient2(SQClient): | ||
def rev(self): | ||
msg = self.send_with_action(msg=b"", action=b"deq", recv=True) | ||
msg = msg.decode() | ||
return msg[::-1] | ||
def get_logger(): | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
ch = logging.StreamHandler() | ||
ch.setLevel(logging.DEBUG) | ||
logger.addHandler(ch) | ||
return logger | ||
def main(logger=None): | ||
if logger is None: | ||
logger = get_logger() | ||
p1 = SQClient2() | ||
p2 = SQClient2() | ||
p1.enq(b"P1> This is message one") | ||
p1.enq(b"P2> This is message two") | ||
p2.enq(b"P2> This is message three") | ||
logger.debug("get from P1: ") | ||
msg = p1.deq() | ||
logger.debug(f"msg1: {msg}") | ||
msg = p1.rev() | ||
logger.debug(f"msg2 rev: {msg}") | ||
logger.debug("get from P2: ") | ||
msg = p2.rev() | ||
logger.debug(f"msg3 rev: {msg}") | ||
msg = p2.deq() | ||
logger.debug(f"msg P2: (should be empty) = {msg}") | ||
msg = p1.deq() | ||
logger.debug(f"msg P1: (should be empty) = {msg}") | ||
if __name__ == '__main__': | ||
main() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
Server Example | ||
============== | ||
|
||
.. code-block:: python | ||
from stiqueue.sqserver import SQServer | ||
class SQServer2(SQServer): | ||
def other_actions(self, action_msg): | ||
action = action_msg[:self.action_len] | ||
if len(action_msg) >= self.action_len: | ||
msg = action_msg[self.action_len:] | ||
if action == b"rev": | ||
self.enq(msg[::-1]) | ||
elif action == b"prt": | ||
self.logger.debug("printing the queue: ") | ||
for i, msg in enumerate(self.q): | ||
self.logger.debug("q(%d)> %s" % (i, msg)) | ||
else: | ||
self.logger.error("ERROR: invalid action:") | ||
self.logger.error(action_msg) | ||
self.logger.error(action) | ||
else: | ||
self.logger.error("Error: invalid action length:") | ||
self.logger.error(action_msg) | ||
self.logger.error(action) | ||
if __name__ == '__main__': | ||
server = SQServer2() | ||
server.listen() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
||
<title>Examples — stiqueue 1.1.1 documentation</title> | ||
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=4f649999" /> | ||
<link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=039e1c02" /> | ||
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js?v=7a812f30"></script> | ||
<script src="_static/doctools.js?v=888ff710"></script> | ||
<script src="_static/sphinx_highlight.js?v=4825356b"></script> | ||
<link rel="index" title="Index" href="genindex.html" /> | ||
<link rel="search" title="Search" href="search.html" /> | ||
<link rel="next" title="Client Example" href="examples/client_example.html" /> | ||
<link rel="prev" title="stiqueue package" href="stiqueue.html" /> | ||
|
||
<link rel="stylesheet" href="_static/custom.css" type="text/css" /> | ||
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" /> | ||
|
||
</head><body> | ||
|
||
|
||
<div class="document"> | ||
<div class="documentwrapper"> | ||
<div class="bodywrapper"> | ||
|
||
|
||
<div class="body" role="main"> | ||
|
||
<section id="examples"> | ||
<span id="id1"></span><h1>Examples<a class="headerlink" href="#examples" title="Permalink to this heading">¶</a></h1> | ||
<div class="toctree-wrapper compound"> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="examples/client_example.html">Client Example</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="examples/server_example.html">Server Example</a></li> | ||
</ul> | ||
</div> | ||
</section> | ||
|
||
|
||
</div> | ||
|
||
</div> | ||
</div> | ||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation"> | ||
<div class="sphinxsidebarwrapper"> | ||
<h1 class="logo"><a href="index.html">stiqueue</a></h1> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<h3>Navigation</h3> | ||
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p> | ||
<ul class="current"> | ||
<li class="toctree-l1"><a class="reference internal" href="stiqueue.html">stiqueue package</a></li> | ||
<li class="toctree-l1 current"><a class="current reference internal" href="#">Examples</a><ul> | ||
<li class="toctree-l2"><a class="reference internal" href="examples/client_example.html">Client Example</a></li> | ||
<li class="toctree-l2"><a class="reference internal" href="examples/server_example.html">Server Example</a></li> | ||
</ul> | ||
</li> | ||
</ul> | ||
|
||
<div class="relations"> | ||
<h3>Related Topics</h3> | ||
<ul> | ||
<li><a href="index.html">Documentation overview</a><ul> | ||
<li>Previous: <a href="stiqueue.html" title="previous chapter">stiqueue package</a></li> | ||
<li>Next: <a href="examples/client_example.html" title="next chapter">Client Example</a></li> | ||
</ul></li> | ||
</ul> | ||
</div> | ||
<div id="searchbox" style="display: none" role="search"> | ||
<h3 id="searchlabel">Quick search</h3> | ||
<div class="searchformwrapper"> | ||
<form class="search" action="search.html" method="get"> | ||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> | ||
<input type="submit" value="Go" /> | ||
</form> | ||
</div> | ||
</div> | ||
<script>document.getElementById('searchbox').style.display = "block"</script> | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</div> | ||
</div> | ||
<div class="clearer"></div> | ||
</div> | ||
<div class="footer"> | ||
©2024, Ahmad Alobaid. | ||
|
||
| | ||
Powered by <a href="http://sphinx-doc.org/">Sphinx 7.1.2</a> | ||
& <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a> | ||
|
||
| | ||
<a href="_sources/examples.rst.txt" | ||
rel="nofollow">Page source</a> | ||
</div> | ||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
Oops, something went wrong.