[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(n-for-each-par-map 16 store download (reverse (iota (max-id))))) crash

From: Amirouche Boubekki
Subject: (n-for-each-par-map 16 store download (reverse (iota (max-id))))) crash
Date: Thu, 05 Jul 2018 13:28:58 +0200
User-agent: Roundcube Webmail/1.1.2

I have a program that try to download hackernews locally.

What it does is simple, it fetch the max identifier and
http-get each json value starting with the most recent
item. I use n-for-each-par-map with 16 threads I have
8 cores.

Here is the full program:

(define-module (hn))

(use-modules (srfi srfi-1))
(use-modules (ice-9 receive))
(use-modules (ice-9 threads))
(use-modules (ice-9 iconv))
(use-modules (web client))
(use-modules (json))

(define (max-id)
(receive (response body) (http-get "";)
    (string->number (bytevector->string body "utf-8"))))

(define (download uid)
  (catch #t
    (lambda ()
      (let* ((uid (1+ uid))
             (url "";)
             (url (format #f url uid)))
        (cons uid
               (call-with-values (lambda () (http-get url))
                 (lambda (response body)
                   (bytevector->string body "utf-8")))))))
    (lambda _ '())))

(define (store pair)
  (if (null? pair)
      (format #t "X\n")
      (let ((port (open-file "hn.scm" "a")))
        (format #t "~a\n" (car pair))
        (write (cdr pair) port)
        (close port))))

(define (dump)
  (n-for-each-par-map 16 store download (reverse (iota (max-id)))))


It also requires json module from

How can I debug this?

Amirouche ~ amz3 ~

reply via email to

[Prev in Thread] Current Thread [Next in Thread]