4

I use APScheduler to schedule a job which calls an API every minute. I now get a massive error which ends with:

  File "/usr/lib/python2.7/httplib.py", line 1045, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 409, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 365, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/lib/python2.7/ssl.py", line 341, in recv
    return self.read(buflen)
  File "/usr/lib/python2.7/ssl.py", line 260, in read
    return self._sslobj.read(len)
SSLError: The read operation timed out
WARNING:apscheduler.scheduler:Execution of job "getAndStoreAPICallResult 
(trigger: cron[minute='*'], next run at: 2014-07-08 15:37:00)" skipped: maximum 
number of running instances reached (1)

So I guess that the API call somehow doesn't get a response and therefore never finishes. This inhibits running the next job, because the first has never ended. Because of this, it somehow cannot start running a new job.

I could of course increase the number of allowed concurrent running instances, but that wouldn't really solve the problem. I guess I need to make the job end if it hasn't finished after a certain number of seconds (lets say 5).

Because I've got a couple other API-call-jobs that I start with APScheduler it would be awesome if I can somehow solve this using APScheduler. Does anybody know if APScheduler makes it possible to terminate too long running jobs, or do I need to solve this in another way?

All tips are welcome!

kramer65
  • 50,427
  • 120
  • 308
  • 488
  • How do you propose to forcibly terminate a thread? – Alex Grönholm Jul 08 '14 at 17:06
  • @AlexGrönholm - I don't know, I'm not really a guru in threads (just started with it last month). That's why I'm looking for suggestions. I don't really know what to do in this situation. Is there no easy way to kill the threads? – kramer65 Jul 09 '14 at 09:57
  • this might help http://docs.python-requests.org/en/master/user/advanced/#timeouts – PirateApp Mar 24 '18 at 01:53

1 Answers1

0

Since there is no way to terminate a thread from outside, consider setting a shorter SSL timeout.

Alex Grönholm
  • 5,563
  • 29
  • 32
  • Ehm.. that might be an idea. I just searched for things like "set ssl timeout ubuntu server", but I can't really find anything. Would you have any idea where I could set that? – kramer65 Jul 10 '14 at 13:19
  • 1
    Start by using the "requests" library for HTTP connections instead of the standard library's httplib. Requests is so much more sophisticated. Then: http://docs.python-requests.org/en/latest/user/quickstart/?highlight=timeout#timeouts – Alex Grönholm Jul 11 '14 at 18:20