0

I'm developing a matchmaking system with gae and python. I was finding a consistent system for automatic matchmaking, and I found the task queue. I implemented a cron job to run every 10 minutes to add a queue. However I'm getting the following error:

When running /queue_generator:
Traceback (most recent call last):
File"/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in Handle
    result = handler(dict(self._environ), self._StartResponse)
TypeError: 'module' object is not callable

The code that I have is: (SessionID is just a db model) queue_generator.py

import webapp2, time
from main import SessionID
from google.appengine.api import taskqueue
from google.appengine.ext import db

class Game(db.Model):
    Users = db.ListProperty(str)
    Score = db.IntegerProperty()
    Turn = db.StringProperty()
class MainHandler(webapp2.RequestHandler):
    def get(self):
        taskqueue.add(url='/matchcreator',params={"id":str(time.time())})

class Gamegenerator(webapp2.RequestHandler):
    def get(self):
        while True:
            q = Queue.get()
           if len(q.queue) >= 4:
                sids = []
                for i in range(0,3):
                    sids.append(q.queue[i])
                    q.queue.remove(i)
                    q.put()
        return self.response.set_status(204)
    def post(self):
        while True:
            q = Queue.get()
        if len(q.queue) >= 4:
            sids = []
            for i in range(0,3):
                sids.append(q.queue[i])
                q.queue.remove(i)
                q.put()
    return self.response.set_status(204)

app = webapp2.WSGIApplication([
    ('/queue_generator', MainHandler),
    ("/matchcreator",Gamegenerator)
], debug=True)

Why is this error occuring?

Edit

app.yaml

application: brobbinsgame
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico
- url: /css
  static_dir: css
- url: /home.css
  static_files: style.css
  upload: style.css
  application_readable: true
- url: /register
  script: register.app
- url: /logout
  script: logout.app
- url: /line
  script: line.app

- url: /queue_generator
  script: queue_generator
  login: admin
- url: /home
  script: home.app
- url: /resetsid
  script: resetsid.app
  login: admin
- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: pycrypto
  version: "latest"
Community
  • 1
  • 1
Dashadower
  • 632
  • 1
  • 6
  • 20

2 Answers2

1

For every path except "/queue_generator, you have correctly referenced the app object. But for that one path, you reference the module directly. You need to define it in exactly the same way:

- url: /queue_generator
  script: queue_generator.app
  login: admin

Also notice that there is no way to get to "/matchcreator": "/queue_generator" is the only URL that will be routed to that file. You need to either expose "/matchcreator" in app.yaml as well, or do the more usual thing which is to route all the paths to a main app which imports all the handlers and defines the specific routing there.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
0

This error is occurring because you are calling a Module instead of a Class.. the call should be : Module.Class.Method()

MayK
  • 1,269
  • 1
  • 10
  • 24