Browse Source

Threading, Web App

pull/75/merge
Jure Šorn 2 weeks ago
parent
commit
767d5e8381
2 changed files with 8 additions and 8 deletions
  1. 6
      README.md
  2. 10
      index.html

6
README.md

@ -2263,7 +2263,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed
```python ```python
<Thread> = Thread(target=<function>) # Use `args=<collection>` to set the arguments. <Thread> = Thread(target=<function>) # Use `args=<collection>` to set the arguments.
<Thread>.start() # Starts the thread. Also <Thread>.is_alive(). <Thread>.start() # Starts the thread. Also <Thread>.is_alive().
<Thread>.join() # Waits for the thread to finish.
<Thread>.join() # Waits for the thread to finish executing.
``` ```
* **Use `'kwargs=<dict>'` to pass keyword arguments to the function.** * **Use `'kwargs=<dict>'` to pass keyword arguments to the function.**
* **Use `'daemon=True'`, or the program will not be able to exit while the thread is alive.** * **Use `'daemon=True'`, or the program will not be able to exit while the thread is alive.**
@ -2563,7 +2563,7 @@ app.run(host=None, port=None, debug=None) # Or: $ flask --app FILE run [--ARG[=
```python ```python
@app.route('/img/<path:filename>') @app.route('/img/<path:filename>')
def serve_file(filename): def serve_file(filename):
return fl.send_from_directory('dirname/', filename)
return fl.send_from_directory('DIRNAME/', filename)
``` ```
### Dynamic Request ### Dynamic Request
@ -2574,7 +2574,7 @@ def serve_html(sport):
``` ```
* **`'fl.render_template(filename, <kwargs>)'` renders a file located in 'templates' dir.** * **`'fl.render_template(filename, <kwargs>)'` renders a file located in 'templates' dir.**
* **`'fl.abort(<int>)'` returns error code and `'return fl.redirect(<url>)'` redirects.** * **`'fl.abort(<int>)'` returns error code and `'return fl.redirect(<url>)'` redirects.**
* **`'fl.request.args[<str>]'` returns parameter from the query string (URL right of '?').**
* **`'fl.request.args[<str>]'` returns parameter from query string (URL part right of '?').**
* **`'fl.session[<str>] = <obj>'` stores session data. It requires secret key to be set at the startup with `'app.secret_key = <str>'`.** * **`'fl.session[<str>] = <obj>'` stores session data. It requires secret key to be set at the startup with `'app.secret_key = <str>'`.**
### REST Request ### REST Request

10
index.html

@ -55,7 +55,7 @@
<body> <body>
<header> <header>
<aside>February 7, 2025</aside>
<aside>February 9, 2025</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a> <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header> </header>
@ -1850,7 +1850,7 @@ delattr(&lt;obj&gt;, <span class="hljs-string">'&lt;name&gt;'</span>)
<div><h3 id="thread">Thread</h3><pre><code class="python language-python hljs">&lt;Thread&gt; = Thread(target=&lt;function&gt;) <span class="hljs-comment"># Use `args=&lt;collection&gt;` to set the arguments.</span> <div><h3 id="thread">Thread</h3><pre><code class="python language-python hljs">&lt;Thread&gt; = Thread(target=&lt;function&gt;) <span class="hljs-comment"># Use `args=&lt;collection&gt;` to set the arguments.</span>
&lt;Thread&gt;.start() <span class="hljs-comment"># Starts the thread. Also &lt;Thread&gt;.is_alive().</span> &lt;Thread&gt;.start() <span class="hljs-comment"># Starts the thread. Also &lt;Thread&gt;.is_alive().</span>
&lt;Thread&gt;.join() <span class="hljs-comment"># Waits for the thread to finish.</span>
&lt;Thread&gt;.join() <span class="hljs-comment"># Waits for the thread to finish executing.</span>
</code></pre></div> </code></pre></div>
<ul> <ul>
@ -2096,7 +2096,7 @@ app.run(host=<span class="hljs-keyword">None</span>, port=<span class="hljs-keyw
</ul> </ul>
<div><h3 id="staticrequest">Static Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@app.route('/img/&lt;path:filename&gt;')</span> <div><h3 id="staticrequest">Static Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@app.route('/img/&lt;path:filename&gt;')</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">serve_file</span><span class="hljs-params">(filename)</span>:</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">serve_file</span><span class="hljs-params">(filename)</span>:</span>
<span class="hljs-keyword">return</span> fl.send_from_directory(<span class="hljs-string">'dirname/'</span>, filename)
<span class="hljs-keyword">return</span> fl.send_from_directory(<span class="hljs-string">'DIRNAME/'</span>, filename)
</code></pre></div> </code></pre></div>
<div><h3 id="dynamicrequest">Dynamic Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@app.route('/&lt;sport&gt;')</span> <div><h3 id="dynamicrequest">Dynamic Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@app.route('/&lt;sport&gt;')</span>
@ -2107,7 +2107,7 @@ app.run(host=<span class="hljs-keyword">None</span>, port=<span class="hljs-keyw
<ul> <ul>
<li><strong><code class="python hljs"><span class="hljs-string">'fl.render_template(filename, &lt;kwargs&gt;)'</span></code> renders a file located in 'templates' dir.</strong></li> <li><strong><code class="python hljs"><span class="hljs-string">'fl.render_template(filename, &lt;kwargs&gt;)'</span></code> renders a file located in 'templates' dir.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'fl.abort(&lt;int&gt;)'</span></code> returns error code and <code class="python hljs"><span class="hljs-string">'return fl.redirect(&lt;url&gt;)'</span></code> redirects.</strong></li> <li><strong><code class="python hljs"><span class="hljs-string">'fl.abort(&lt;int&gt;)'</span></code> returns error code and <code class="python hljs"><span class="hljs-string">'return fl.redirect(&lt;url&gt;)'</span></code> redirects.</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'fl.request.args[&lt;str&gt;]'</span></code> returns parameter from the query string (URL right of '?').</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'fl.request.args[&lt;str&gt;]'</span></code> returns parameter from query string (URL part right of '?').</strong></li>
<li><strong><code class="python hljs"><span class="hljs-string">'fl.session[&lt;str&gt;] = &lt;obj&gt;'</span></code> stores session data. It requires secret key to be set at the startup with <code class="python hljs"><span class="hljs-string">'app.secret_key = &lt;str&gt;'</span></code>.</strong></li> <li><strong><code class="python hljs"><span class="hljs-string">'fl.session[&lt;str&gt;] = &lt;obj&gt;'</span></code> stores session data. It requires secret key to be set at the startup with <code class="python hljs"><span class="hljs-string">'app.secret_key = &lt;str&gt;'</span></code>.</strong></li>
</ul> </ul>
<div><h3 id="restrequest">REST Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@app.post('/&lt;sport&gt;/odds')</span> <div><h3 id="restrequest">REST Request</h3><pre><code class="python language-python hljs"><span class="hljs-meta">@app.post('/&lt;sport&gt;/odds')</span>
@ -2931,7 +2931,7 @@ $ deactivate <span class="hljs-comment"># Deactivates the active
<footer> <footer>
<aside>February 7, 2025</aside>
<aside>February 9, 2025</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a> <a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer> </footer>

Loading…
Cancel
Save