mirror of
https://github.com/Xevion/thedrank.com.git
synced 2025-12-11 08:08:55 -06:00
multiprocessing counter value
This commit is contained in:
@@ -1,15 +1,18 @@
|
|||||||
from app import app
|
from app import app
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
|
from multiprocessing import Value
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
viewcountpath = os.path.join('app', 'static', 'viewcount.dat')
|
viewcountpath = os.path.join('app', 'static', 'viewcount.dat')
|
||||||
i = int(open(viewcountpath, 'r').read())
|
counter = Value('i', int(open(viewcountpath, 'r').read()))
|
||||||
|
|
||||||
def getIncrement(n=1):
|
def getIncrement(n=1):
|
||||||
global i
|
global i
|
||||||
i += n
|
with counter.get_lock():
|
||||||
open(viewcountpath, 'w').write(str(i))
|
counter.value += n
|
||||||
return i
|
open(viewcountpath, 'w').write(str(counter.value))
|
||||||
|
return counter.value
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
|
|||||||
Reference in New Issue
Block a user