title: Threading Class - 'int' not iterable | Flask
body: <p>I'm current encountering an issue where I'm using threads to perform tasks in the background upon a POST request, but I'm having an issue with using an integer as a parameter; or any data type as a parameter for that matter.
  <br />
  <br />
  What is supposed to happen is that it's supposed to perform everything inside of the POST request check, then perform something else after that has been completed.</p>
  <p>Imports:</p>
  <pre><code>from flask import Flask, url_for, render_template, redirect, request
  from flask.cli import with_appcontext, click
  import sqlalchemy
  from flask_sqlalchemy import SQLAlchemy
  from flask_login import LoginManager, login_required, current_user
  </code></pre>
  <p>Thread Class:</p>
  <pre><code>@click.command(name='run')
  @click.pass_context
  class Compute(Thread):
      def __init__(self, secs):
          Thread.__init__(self)
          self.secs = secs
  
      def run(self):
          print('Thread Opened')
          sleep(self.secs)
          db.session.query(Users).filter(Users.username == current_user.username).first().requests += 1
          db.session.commit()
          print('Thread Closed')
  </code></pre>
  <p>Flask Route:</p>
  <pre><code>@app.route('/index', methods=['GET', 'POST'])
  @login_required
  def index():
      if request.method == 'POST':
          time = '5'
  
          thread = Compute(int(time))
          thread.start()
          return redirect(url_for('index'))
      else:   
          return render_template('index.html')
  </code></pre>
  <p>The error I am receiving when the thread tries to start is this:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\flask\app.py&quot;, line 2447, in wsgi_app
      response = self.full_dispatch_request()
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\flask\app.py&quot;, line 1952, in full_dispatch_request    rv = self.handle_user_exception(e)
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\flask\app.py&quot;, line 1821, in handle_user_exception    reraise(exc_type, exc_value, tb)
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\flask\_compat.py&quot;, line 39, in reraise
      raise value
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\flask\app.py&quot;, line 1950, in full_dispatch_request    rv = self.dispatch_request()
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\flask\app.py&quot;, line 1936, in dispatch_request     
      return self.view_functions[rule.endpoint](**req.view_args)
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\flask_login\utils.py&quot;, line 272, in decorated_view    return func(*args, **kwargs)
    File &quot;c:/Users/myuser/Desktop/Projects/Python/app.py&quot;, line 104, in layer4
      thread = Compute(int(time))
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\click\core.py&quot;, line 829, in __call__
      return self.main(*args, **kwargs)
    File &quot;C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\click\core.py&quot;, line 767, in main
      args = list(args)
  TypeError: 'int' object is not iterable
  </code></pre>
  <p>I am not very experienced with threading, I've only dabbled with it in other projects so I'm not sure why I'm getting this error; any help is greatly appreciated.</p>