A
A
AlexSer2019-09-10 08:44:27
Python
AlexSer, 2019-09-10 08:44:27

How to organize version control?

Hello!
Not long ago, this question appeared :
Let's say I have a web application in PHP. But, every time it is added and expanded, I add functions, improve something, remove something. The web application is already running in two organizations. And they are different, since one of the organizations asks to add reports, respectively, the files began to differ.
How to organize the application so that it itself controls the versions of files, and if at least one file is different, so that it warns. Just the other day I downloaded a newer file automatically and there were problems.
I want my application to be in control of the versions of its files.
Tell me where and what to read, what to watch or how you solved this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2018-03-28
@OlegPyatakov

Firstly, global dequethis is not about multithreading, but about the visibility of variables.
Secondly, the error is actually in this part of the code:

if r not in deque:
      deque.append(r);

A potential bug may appear at this point if there is a race between threads. If you add a minimal time.sleep at this point (or another "time-consuming" operation), then everything immediately starts to break. I'm not ready to say right off the bat why no error occurs without time.sleep in the unmodified case (probably due to the operation of runtime and the GIL). However, the fact that the thread will not go to sleep in this place is not guaranteed by the runtime and you cannot bet on it.
To see the error, I slightly modified the script: added sleep and increased the number of threads). In this form, it turns out that 170 numbers are added against 101 unique ones.
import threading;
import random;
import collections;

from time import sleep

NUM_THREADS = 50;
COUNT_FOR_EACH_THREAD = 10;
threads = [];
deque = collections.deque();


def threadProc():
  for i in range(0, COUNT_FOR_EACH_THREAD):
    r = random.randint(0, 100);
    if r not in deque:
      sleep(0.01)
      deque.append(r);


for i in range(0, NUM_THREADS):
  thread = threading.Thread(target = threadProc);
  threads.append(thread);
  thread.start();
  
for i in range(0, NUM_THREADS):
  threads[i].join();

print(deque);
print(len(deque))
print(len(set(deque)))

PS. In Python, it makes no sense to end lines with ";".

M
Maxim, 2019-09-10
@AlexSer

If you do not use Git for these purposes, then you can do it in a simple way: compare the checksums of the files https://php.net/manual/en/function.hash-file.php
And if the amounts differ, then the file has been changed. You can signal this, say, by mail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question